views:

61

answers:

0

Say I have a regular Business Method that accepts a parameter object which uses DataAnnotations. Example:

public class Contact {
      [Required]
      [StringLength(50)]
      public string FirstName { get; set;}

      // other properties and methods
}

public void SetContact(Contact contact) {
    // Execute a method to make sure the contact is valid
}

Is there anyway to trigger these validations in the SetContact method without going through the System.Reflection and triggering every attribute individually?

I am aware that MVC binder has a way to enable this for action methods by using Microsoft.Web.Mvc.DataAnnotations , is there any existing implementation that does the same for regular methods?