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

Constrain allowed values #2

Open
mookid8000 opened this issue Oct 8, 2015 · 0 comments
Open

Constrain allowed values #2

mookid8000 opened this issue Oct 8, 2015 · 0 comments

Comments

@mookid8000
Copy link
Member

Similar to how [Example("whatever")] can be used to show example values, an [AllowedValue("someValue")] attribute should be used to specify which values are allowed.

Could be simple like the one above - could also be more advanced as in:

[Parameter("n")]
[AllowedValue("a prime: 2, 3, 5, 7, ...", validator: typeof(PrimeChecker))]
public int N { get; set; }

where PrimeChecker could then be an IValidator:

public class PrimeChecker : IValidator
{
    public void Validate(string value, Arguments accessToTheOtherArguments)
    {
        if (!ValueIsPrime(int.Parse(value))) {
            throw new GoCommandoException($"Value '{value}' is not prime!");
        }
    }
}

Not sure yet what would work best. Could start out with the simple one.

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

1 participant