title: FluentValidation validate Enum value
body: <p>I have the following model:</p>
  
  <pre><code>public class ViewDataItem
  {
      public string viewName { get; set; }
      public UpdateIndicator updateIndicator { get; set; }
  }
  </code></pre>
  
  <p>With the following enum:</p>
  
  <pre><code>public enum UpdateIndicator
  {
      Original,
      Update,
      Delete
  }
  </code></pre>
  
  <p>And the following Validator:</p>
  
  <pre><code>public class ViewValidator : AbstractValidator&lt;ViewDataItem&gt;
  {
      public ViewValidator()
      {
          RuleFor(x =&gt; x.viewName).NotEmpty().WithMessage("View name must be specified");
          RuleFor(x =&gt; x.updateIndicator).SetValidator(new UpdateIndicatorEnumValidator&lt;UpdateIndicator&gt;());
      }
  }
  
  public class UpdateIndicatorEnumValidator&lt;T&gt; : PropertyValidator
  {
      public UpdateIndicatorEnumValidator() : base("Invalid update indicator") {}
  
      protected override bool IsValid(PropertyValidatorContext context)
      {
          UpdateIndicator enumVal = (UpdateIndicator)Enum.Parse(typeof(UpdateIndicator), context.PropertyValue.ToString());
  
          if (!Enum.IsDefined(typeof(UpdateIndicator), enumVal))
            return false;
  
          return true;
      }
  }
  </code></pre>
  
  <p>The code is in a WebAPI that receives data via JSON, deserialize it to an object and then validates, but for some reason I can send whatever I please in the <code>updateIndicator</code>, so long as I don't put in an integer value larger than the max index in the enum (i.e 1,2 or 3 works fine, but 7 will generate an error).</p>
  
  <p>How can I get this to validate the input of the data I receive to see if that value is actually in the Enum?</p>