I'm using the InstallContext class to parse the command-line arguments of a console application. The arguments are in the form of "-file=myFile.txt -flag", and the InstallContext object gives me what I need through the Parameters and IsParameterTrue properties.
However, I can't find any documentation or code samples that confirm that this is an acceptable use of the InstallContext class. I understand the need to use Regex or some other means to parse more complex command-line arguments, but I'm surprised to find no mention of this simple parsing alternative. Is there anything wrong with using InstallContext for this purpose
using System;
using System.Configur ation.Install;
using System.Collecti ons.Specialized ;
class MyClass
{
public static void Main(string[] args)
{
InstallContext context = new InstallContext( null, args);
StringDictionar y parameters = context.Paramet ers;
string file = parameters["file"];
bool flag = context.IsParam eterTrue("flag" );
Console.WriteLi ne("file = {0}", file);
Console.WriteLi ne("flag = {0}", flag);
}
}
However, I can't find any documentation or code samples that confirm that this is an acceptable use of the InstallContext class. I understand the need to use Regex or some other means to parse more complex command-line arguments, but I'm surprised to find no mention of this simple parsing alternative. Is there anything wrong with using InstallContext for this purpose
using System;
using System.Configur ation.Install;
using System.Collecti ons.Specialized ;
class MyClass
{
public static void Main(string[] args)
{
InstallContext context = new InstallContext( null, args);
StringDictionar y parameters = context.Paramet ers;
string file = parameters["file"];
bool flag = context.IsParam eterTrue("flag" );
Console.WriteLi ne("file = {0}", file);
Console.WriteLi ne("flag = {0}", flag);
}
}
Comment