I'm struggling with implementing a validator for a class, where only one property should be set.
Let's say we have the following class:
public class SomeClass
{
public DateTime SomeDate {get; set;}
public IEnumerable<int> FirstOptionalProperty {get; set;}
public IEnumerable<int> SecondOptionalProperty {get; set;}
public IEnumerable<int> ThirdOptionalProperty {get; set;}
}
This class has one mandatory property - SomeDate. Other properties are optional and only one can be set e.g if FirstOptionalProperty is set - SecondOptionalProperty and ThirdOptionalProperty should be null, if SecondOptionalProperty is set - FirstOptionalProperty and ThirdOptionalProperty should be null and so forth.
In other words: if one of IEnumerable props is set - other IEnumerables should be null.
Any tips/ideas on implementing validator for such type of class? The only thing I came up with is writing chunks of When rules, but this way of writing code is error prone and result looks ugly.