Validation: One property validation should fire if other property isn't null

Topics: Validation Application Block
Jun 1, 2009 at 1:54 PM

Hi!

Say I have a class with two properties, ContactName and ContactPhone. Is it possible to have a check that if ContactName isn't null, ContactPhone must not also be null?

something like:

public class Contact
{
    public string ContactPersonName { get; set; }
    [OnlyCheckIfThisPropertyIsNotNull("ContactPersonName")]
    [NotNullValidator]
    public string ContactPersonPhone { get; set; }
}

Is it possible?

Best regards,
Mats

Jun 2, 2009 at 4:45 AM

Hi,

I think you can do this using the SelfValidation of the Validation Application Block. http://msdn.microsoft.com/en-us/library/cc511640.aspx - self validation tutorial.

Related Link:

http://entlib.codeplex.com/Thread/View.aspx?ThreadId=43757

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com