Analze Command

The Analyze Command does not really do mathematics, but it analyzes the plain arguments as specified in the command-line. If you don't want to use a Context you can always directly use the IArgumentCollection.

IArgumentCollection arguments 
    = ServiceProvider.GetRequiredService<IArgumentCollection>();

for(int i=0; i<arguments.Count; i++)
{
    Argument argument = arguments[i];
    switch (argument.Type)
    {
        case ArgumentType.Verb:
            Console.WriteLine($"{i:2} {argument.Type}  : {argument.Key}");    
            break;
        case ArgumentType.Option:
            Console.WriteLine($"{i:2} {argument.Type}: {argument.Key}={argument.Value}");    
            break;
        case ArgumentType.Target:
            Console.WriteLine($"{i:2} {argument.Type}: {argument.Value}");    
            break;
        default:
            throw new ArgumentOutOfRangeException();
    }
}
> demo3App.exe MATH ANALYZE /v=2 "c:\Windows"

1 Verb  : MATH
2 Verb  : ANALYZE
3 Option: v=2
4 Target: "c:\Windows"

Last updated