Is there ValidationAttribute in .net for closed set of values?
For instance in the code below, only "a", "b" and "c" are the valid values for StringType property, and 1, 10, 100 are the only allowed values for IntType
public record RequestModel
{
[StringOptions("a", "b", "c")
public string StringType{get; init;}
[IntOptions(1, 10, 100)
public string IntType{get; init;}
}
10x.
For Older versions there is no built-in
ValidationAttributethat allows a property to have a closed set of specific values directly in the way you're describing withStringOptionsorIntOptionsCreate a Ccustom validation attributes
For better validation rules use Fluent Validator it provides lot of features.