title: C# Custom Attribute Required If
body: <p>I am just getting into custom attributes, and I absolutely love them. I am wondering if it is possible to create an attribute that gets applied to a property and denotes the name of another property in the same object. If would check to see if the referenced property has a value, and if so, the decorated attribute would be required.
  Something like this:</p>
  
  <pre><code>[RequiredIfNotNull("ApprovedDate")]
  [DisplayName("Approved By")]
  [StringLength(50, ErrorMessage = "{0} must not exceed {1} characters")]
  public string ApprovedBy { get; set; }
  
  [DisplayName("Approved Date")]
  [DisplayFormat(DataFormatString = "{0:d}")]
  [PropertyMetadata(ColumnName = "ApprovedDate")]
  public DateTime? ApprovedDate { get; set; }
  </code></pre>
  
  <p>So the approved by property is decorated with the RequiredIfNotNull attribute which references the property to check for null. In this case, the Approved Date.
  I would want the ApprovedBy Property to be required if the ApprovedDate had a value.
  Is it possible to do something like this?
  If so can you implement it server side and client side?</p>