ValidateRequiredIfEquals

Description: Indicates a property is required if another property equals a certain value.

Constructor(s):
  • public ValidateRequiredIfEqualsAttribute(string propertyName, string propertyValue, string message)

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

Example Usage:
public class MyEntity : EvilBaseEntity
{
    [ValidateRequiredIfEquals("Property2", "D", "Property1 is required if Property2 equals 'D'.")]
    public string Property1
    {
        // Omitted for brevity
    }

    public string Property2
    {
        // Omitted for brevity
    }
}


Valid Entity 1:
MyEntity entity = new MyEntity();
entity.Property1 = "SomeValue";
entity.Property2 = "D";

bool result = entity.IsValid();


Valid Entity 2:
MyEntity entity = new MyEntity();
entity.Property1 = "SomeValue";
entity.Property2 = "A";

bool result = entity.IsValid();


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

bool result = entity.IsValid();


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

bool result = entity.IsValid();


Invalid Entity 1:
MyEntity entity = new MyEntity();
entity.Property1 = null;
entity.Property2 = "D";

bool result = entity.IsValid();


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

bool result = entity.IsValid();

Last edited Dec 7, 2006 at 3:20 PM by Arcware, version 1

Comments

No comments yet.