title: Can I manually validate a property using a custom validation attribute?
body: <p>I have a custom <code>ValidationAttribute</code>, however I only want to validate this property if a CheckBox is checked.</p>
  
  <p>I've made my class inherit from <code>IValidationObject</code> and am using the <code>Validate</code> method to perform any custom validation, however can I use a custom <code>ValidationAttribute</code> here instead of duplicating the code? And if so, how?</p>
  
  <pre><code>public class MyClass : IValidatableObject
  {
      public bool IsReminderChecked { get; set; }
      public bool EmailAddress { get; set; }
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          if (IsReminderChecked)
          {
              // How can I validate the EmailAddress field using
              // the Custom Validation Attribute found below?
          }
      }
  }
  
  
  // Custom Validation Attribute - used in more than one place
  public class EmailValidationAttribute : ValidationAttribute
  {
      public override bool IsValid(object value)
      {
          var email = value as string;
  
          if (string.IsNullOrEmpty(email))
              return false;
  
          try
          {
              var testEmail = new MailAddress(email).Address;
          }
          catch (FormatException)
          {
              return false;
          }
  
          return true;
      }
  }
  </code></pre>