title: Is there out-of-the box validator for Enum values in DataAnnotations namespace?
body: <p>C# enum values are not limited to only values listed in it's definition and may store any value of it's base type. If base type is not defined than <code>Int32</code> or simply <code>int</code> is used.</p>
  
  <p>I am developing a WCF serivice which needs to be confident that some enum has a value assigned as opposed to the default value for all enums of 0. I start with a unit test to find out whether <code>[Required]</code> would do right job here.</p>
  
  <pre><code>using System.ComponentModel.DataAnnotations;
  using Xunit;
  
  public enum MyEnum
  {
      // I always start from 1 in order to distinct first value from the default value
      First = 1,
      Second,
  }
  
  public class Entity
  {
      [Required]
      public MyEnum EnumValue { get; set; }
  }
  
  public class EntityValidationTests
  {
      [Fact]
      public void TestValidEnumValue()
      {
          Entity entity = new Entity { EnumValue = MyEnum.First };
  
          Validator.ValidateObject(entity, new ValidationContext(entity, null, null));
      }
  
      [Fact]
      public void TestInvalidEnumValue()
      {
          Entity entity = new Entity { EnumValue = (MyEnum)(-126) };
          // -126 is stored in the entity.EnumValue property
  
          Assert.Throws&lt;ValidationException&gt;(() =&gt;
              Validator.ValidateObject(entity, new ValidationContext(entity, null, null)));
      }
  }
  </code></pre>
  
  <p>It does not, the second test does not throw any exception.</p>
  
  <p>My question is: is there a validator attribute to check that supplied value is in <code>Enum.GetValues</code>?</p>
  
  <p><strong>Update</strong>.
  Make sure to use the <code>ValidateObject(Object, ValidationContext, Boolean)</code> with last parameter equal to <code>True</code> instead of <code>ValidateObject(Object, ValidationContext)</code> as done in my unit test.</p>