Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: how to validate enum values

$
0
0

The simplest thing would be to use a Must rule. Simple example:

public enum MyEnum {
   First, Second, Third
}

public class Foo {
  public MyEnum SomeProperty { get; set; }
}

public class FooValidator : AbstractValidator<Foo> {
  public FooValidator() {
    RuleFor(x => x.SomeProperty).Must(x => x == MyEnum.First || x == myEnum.Second); 
  }
}

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>