views:

23

answers:

0

How a can verify if a field of a child is null or empty when verifying the parent object?

Example:

public class Zone {

    [NotNullNotEmpty(Message = "Zone name is required.")]
    public string Name;
    public Foo Foo;

}

public class Foo {

    [NotNullNotEmpty(Message = "Foo bar is required.")]        
    public string Bar;

}

when I do:

Foo foo = new Foo();
foo.Bar = null;
Zone zone = new Zone() { Name = "zonename", Foo = foo };

Validate(zone);
if (!ValidationDictionary.IsValid) return false;

the ValidationDictionary doesn't add the bar null problem.