Inside Command Line Argument Parser – Expression Evaluator
In some cases, you may want to pass some expression as command line arguments and assign them to command line arguments. Cinchoo framework covers this requirement as well.
1. Add a reference to Cinchoo.Core.dll
2. Namespace: Cinchoo.Core.Shell
Let say, you want to pass 100 + 50 as command line argument (N), you can do so as below
N:{100 + 50} /I -O:C:\Log -D:%NOW%
Expressions are given in { and } braces. Please note that the symbols needs to have spaces
Cinchoo framework looks into the {100+50} command line argument value, evaluates and assigns the outcome value to corresponding member (Count).
[ChoCommandLineArgObject(ApplicationName = "Hello World", Copyright = "Copyright (c) Cinchoo Inc.")]
public class MyCommandLineArgObject : ChoCommandLineArgObject
{
[ChoCommandLineArg("D", DefaultValue = "%NOW%", Description = "Business Date.", ShortName = "Today")]
public DateTime Today
{
get;
set;
}
[ChoCommandLineArg("N", DefaultValue = 100, Description = "No of spaces for a TAB.")]
public int Count
{
get;
set;
}
[ChoCommandLineArg("I", DefaultValue = false, FallbackValue = true, Description = "Include Sub directory.")]
public bool IncludeSubDir
{
get;
set;
}
[ChoCommandLineArg("O", IsRequired = true, Description = "Output Directory.")]
public string OutFolder
{
get;
set;
}
[ChoDefaultCommandLineArg(IsRequired = true, Description = "Semi-colon seperated list of folders")]
[ChoTypeConverter(typeof(ChoStringToStringArrayConverter))]
public string[] Folders
{
get;
set;
}
}
If the application containing above type executed with the below command line arguments
N:{100+50}/I -O:C:\Log -D:%NOW%
Or
N:"{100 + 50}"/I -O:C:\Log -D:%NOW%
MyCommandLineArgObject commandLineArgObject = new MyCommandLineArgObject(); Console.WriteLine(commandLineArgObject.ToString());
And run the application, the commandLineArgObject will contain the below values
Hello World [Version 1.0.0.0] Copyright (c) Cinchoo Inc. -- Cinchoo.Core.CommandLineArgs.Test.MyCommandLineArgObject Dump -- Today: 1/6/2012 12:32:00 PM Count: 150 IncludeSubDir: True OutFolder: C:\Log
Please visit ExpressionEvaluator section for more detailed information about expressions.