Refactor Code

  • Gravatar
    Handling Entity Classes Validation

    by azamsharp on 5/6/2008 4:43:47 PM
  • One of the things that I am really interested in entity classes validation. What is the best practice for validating that the entity class is valid. This means validation properties and stuff. I found that using Custom Attributes is a clean approach and also expandable as you can create more custom attributes.

  • public class Customer
    {

    [NotNullOrEmpty]
    public string FirstName
    {
    // whatever
    }

    }

    Customer customer = new Customer();
    // assign values to the customer

    ValidationEngine.Validate(customer);

    if(customer.IsValid) customer.Save();

    else // show the broken rules!


  • Refactor it!
Please log in to refactor the code! Login