Skip to content

Instantly share code, notes, and snippets.

@MichaelPaulukonis
Last active December 26, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelPaulukonis/7217246 to your computer and use it in GitHub Desktop.
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.
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