Skip to content

How to require an option but only if it is specified without a value? #128

Answered by Tyrrrz
rcdailey asked this question in Q&A
Discussion options

You must be logged in to vote

I think you can do it via BindingValidator and by setting the validator on the CommandOption:

[CommandOption("list-terms", Description = "Test", Validators = new[] { typeof(MyValidator)})]

If I remember correctly, the validator is only triggered on the value if the option has been provided, so you would simply handle the null value which would correspond to case 2 in your situation.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@Tyrrrz
Comment options

@rcdailey
Comment options

@Tyrrrz
Comment options

@rcdailey
Comment options

@Tyrrrz
Comment options

Answer selected by rcdailey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants