Skip to content

Constrain allowed values #2

@mookid8000

Description

@mookid8000

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions