Last active
December 26, 2015 21:39
-
-
Save MichaelPaulukonis/7217246 to your computer and use it in GitHub Desktop.
Simple (mis)use of `System.Configuration.Install` to get a simple key-value collection for command-line parameters. Look into nDesk or other tools for something more robust.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Configuration.Install; | |
namespace SimpleCommandlineParms | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var context = new InstallContext(null, args); | |
var parameters = context.Parameters; | |
var key = parameters["key"] ?? string.Empty; // replace string.Empty with default | |
var target = parameters["target"] ?? string.Empty; | |
var flag = ((parameters["flag"] ?? "false").ToLowerInvariant() == "true"); // default to false | |
Console.WriteLine(string.Format("key: {0} target: {1}", key, target)); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment