This project is read-only.

ValidateRequiredIfNotNullOrEmpty

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

Constructor(s):
  • public ValidateRequiredIfNotNullOrEmptyAttribute(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
{
    [ValidateRequiredIfNotNullOrEmpty("Property2", "Property1 is required 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 = "Value1";
entity.Property2 = "Value2";

bool result = entity.IsValid();


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

bool result = entity.IsValid();


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

bool result = entity.IsValid();


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

bool result = entity.IsValid();


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

bool result = entity.IsValid();

Last edited Dec 7, 2006 at 4:32 PM by Arcware, version 1

Comments

No comments yet.