This project is read-only.

How to Use EViL

EViL was designed with two goals in mind: 1) to give developers something useful right out of the box and 2) to give developers an easy way to extend EViL as they see fit.

To Use EViL By Inheriting from EvilBaseEntity

1. Add a reference to the EViL assembly.
2. Make your entities inherit from EvilBaseEntity.
3. Decorate the properties on your entities with whatever combination of attributes you need.
4. Invoke the IsValid method on your entity.

More info about EvilBaseEntity
If you make your entity classes inherit from EvilBaseEntity, either individually or through your own base class, you get the base implementation of the IsValid method and the ValidationErrors collection for free. All you have to do is invoke IsValid and/or iterate through ValidationErrors and you're good to go.
  • IsValid: This method takes care of collecting all the validation attributes on the entity and then invoking them appropriately.
  • ValidationErrors: This string collection contains the list of all error messages that have occured during validation. This collection can be used to display all validation error messages to the user.

Example:

// Assuming entity directly or indirectly inherits from EvilBaseEntity and
// has already been decorated with the appropriate validation attributes
if (entity.IsValid() == false)
{
    // Loop through messages and display to user
    foreach (string message in entity.ValidationErrors)
    {
    }
}

To Use EViL Without Inheriting from EvilBaseEntity

1. Add a reference to the EViL assembly.
2. Decorate the properties on your entities with whatever combination of attributes you need.
3. Create a new instance of the EvilValidator class, giving it the entity you want to validate.
4. Invoke the IsValid method on the EvilValidator class.
5. Iterate through the ValidationErrors collection on the EvilValidator class to display any error messages to the user.

Example:

// Assuming entity has already been decorated with the appropriate validation attributes
EvilValidator ev = new EvilValidator(entity);
if (ev.IsValid() == false)
{
    // Loop through messages and display to user
    foreach (string message in ev.ValidationErrors)
    {
    }
}

To Extend EViL By Creating Your Own Custom Attributes

1. Add a reference to the EViL assembly.
2. Make your own attributes inherit from EvilBaseAttribute.
3. Provide implementation for ValidateValue.

More info about EvilBaseAttribute
All of the EViL attributes inherit from this abstract attribute class, which provides the base constructor and the base Message property. It also provides an abstract method named ValidateValue that all derived classes must implement. Therefore, if you want to create your own custom validation attributes, simply inherit from EvilBaseAttribute and provide the implementation for ValidateValue.

Last edited Dec 20, 2006 at 2:42 PM by Arcware, version 4

Comments

No comments yet.