You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can I specify that certain parameter values are invalid? Something to the same effect of:
private string _server = null;
[Option('s', "server", Required = true, HelpText = "Some text here")]
public virtual string Server
{
get { return _server; }
set { if (string.Compare("localhost", value, true) == 0)
{
_server = null;
throw new ArgumentException("Localhost is not accepted as a server name.");
}
}
}
Of course, I can validate after parsing is complete, but I had to do it in many places. Is there a better way?
Thanks!
The text was updated successfully, but these errors were encountered:
The code you posted should do what you're asking. IMO validation should be separate from parsing, aside from basic things like passing text to an int. There are lots of great libraries for that like Fluent Validation, plus a lot of more complex validation (obj.Age must be >18 if obj.CanVote == true) can't be done until after parsing.
Hi there,
Can I specify that certain parameter values are invalid? Something to the same effect of:
Of course, I can validate after parsing is complete, but I had to do it in many places. Is there a better way?
Thanks!
The text was updated successfully, but these errors were encountered: