ValidateRequiredNullOrEmptyIfNotNullOrEmpty

Description: Indicates a property is required to be null or empty if another property is not null or empty.

Constructor(s):
  • public ValidateRequiredNullOrEmptyIfNotNullOrEmptyAttribute(string propertyName, string message)

Parameters:
  • propertyName: The name of the property to compare.
  • message: The message to be used if validation fails.

Example Usage:
public class MyEntity : EvilBaseEntity
{
    [ValidateRequiredNullOrEmptyIfNotNullOrEmpty("Property2", "Property1 must be null or empty if Property2 is not null or empty.")]
    public string Property1
    {
        // Omitted for brevity
    }

    public string Property2
    {
        // Omitted for brevity
    }
}


Valid Entity 1:
MyEntity entity = new MyEntity();
entity.Property1 = null;
entity.Property2 = "Value2";

bool result = entity.IsValid();


Valid Entity 2:
MyEntity entity = new MyEntity();
entity.Property1 = string.Empty;
entity.Property2 = "Value2";

bool result = entity.IsValid();


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

bool result = entity.IsValid();


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

bool result = entity.IsValid();


Invalid Entity:
MyEntity entity = new MyEntity();
entity.Property1 = "Value1";
entity.Property2 = "Value2";

bool result = entity.IsValid();

Last edited Dec 7, 2006 at 3:52 PM by Arcware, version 2

Comments

No comments yet.