ValidateMaxLength

Description: Indicates a property has a maximum length.

Constructor(s):
  • public ValidateMaxLengthAttribute(int maxLength, string message)

Parameters:
  • maxLength: The maximum length of the property.
  • message: The message to be used if validation fails.

Example Usage:
public class MyEntity : EvilBaseEntity
{
    [ValidateMaxLength(10, "Property1 has a maximum length of 10.")]
    public string Property1
    {
        // Omitted for brevity
    }
}


Valid Entity 1:
MyEntity entity = new MyEntity();
entity.Property1 = "abcdefghij";

bool result = entity.IsValid();


Valid Entity 2:
MyEntity entity = new MyEntity();
entity.Property1 = "abcde";

bool result = entity.IsValid();


Valid Entity 3:
MyEntity entity = new MyEntity();
entity.Property1 = null;

bool result = entity.IsValid();


Valid Entity 4:
MyEntity entity = new MyEntity();
entity.Property1 = string.Empty;

bool result = entity.IsValid();


Invalid Entity:
MyEntity entity = new MyEntity();
entity.Property1 = "abcdefghijklmnopqrstuvwxyz";

bool result = entity.IsValid();


Last edited Dec 20, 2006 at 1:19 PM by Arcware, version 2

Comments

No comments yet.