Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prohibited values #128

Open
raymondb1 opened this issue May 14, 2014 · 2 comments
Open

Prohibited values #128

raymondb1 opened this issue May 14, 2014 · 2 comments

Comments

@raymondb1
Copy link

Hi there,

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!

@raymondb1 raymondb1 changed the title Prohibitted values Prohibited values May 14, 2014
@nemec
Copy link
Collaborator

nemec commented May 14, 2014

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.

@gsscoder
Copy link
Owner

gsscoder commented Jul 9, 2015

I think @nemec was talking about this lib: https://github.com/JeremySkinner/FluentValidation. Right?

@raymondb1, I'm agree with @nemec, anyway I don't think a few validation machinery will never be added to this library too.

In issue #158 we discuss some of this eventual mechanism. Please give a look and back here (or there) to say what you think.

Thank you for choosing this project for you command line parsing needs! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants