Reputation:
Using https://github.com/commandlineparser/commandline
I would like to set an Option as "Required" if the value parsed from another Option is equal to a particular value.
[Option('f', "foo", Required = true, HelpText = "Name of process")]
public string Foo{ get; set; }
[Option('b', "bar", Required = ( Foo == "egg" ), HelpText = "Name of process")]
public string Bar{ get; set; }
Upvotes: 0
Views: 442
Reputation: 2994
I don't think this is possible since .NET Attribute
class has some restrictions to what kinds of arguments may be used with. You have to use a constant expression where you set the Required
property. Your line
[Option('b', "bar", Required = ( Foo == "egg" ), HelpText = "Name of process")]
raises the explanatory compiler error (assuming Foo
is a static property):
CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.
Upvotes: 0