Im working on a console tool which accepts some arguments and then parses to the Option class.
What I need is a property that will verify if only one of many marked fields in Option class has values (arguments were delivered).
Ex. Its ok when we run:
my.exe -a
my.exe -b
but NOT:
my.exe
my.exe -a -b
CommandLine.OptionAttribute cannot do such a thing. What i did is: Main class args[] got extension .Parse:
args.Parse(options)` //where options is my Options class
inside:
CommandLine.Parser.Default.ParseArguments(args, options);
var isOnlyOneOfMany = options.GetType().GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(OneOfMany)) && prop.GetValue(options) != null).Count() == 1;
how to do this better way?