I have three classes in my code - Parent
, Child1
, and Child2
- and I want to validate property Child2.B
only when property Child1.A
has a value. Because A
and B
are in different classes, I'm not sure how to verify A
has a value. For example:
public class Parent {
public Child1 C1 { get; set; }
public Child2 C2 { get; set; }
}
public class Child1 {
public string A { get; set; }
}
public class Child2 {
[IsRequiredOnlyWhenAIsNotNull]
public string B { get; set; }
}
I could perform the validation explicitly; however, I may have quite a few of these sorts of checks so using an attribute would be more convenient.