I would do attribute-based validation:
public class Entity { [Required, MaxStringLength(50)] public string Property1 { get; set; } [Between(5, 20)] public int Property2 { get; set; } [ValidateAlways, Between(0, 5)] public int SomeOtherProperty { get; set; } [Requires("Property1, Property2")] public void OperationX() { } }
Each property that is passed to the Requires attribute must be valid for the operation to complete.
Properties that have the ValidateAlways attribute must always be valid - no matter what operation.
In my pseudo-code, Property1 , Property2 and SomeOtherProperty must be valid to execute OperationX .
Of course, you must add a parameter to the Requires attribute to check the validation attributes for the child. But I canโt suggest how to do this without seeing some sample code.
Maybe something like this:
[Requires("Property1, Property2, Child2: Property3")]
If necessary, you can also use strongly typed property pointers with lambda expressions instead of strings ( Example ).
Arxisos
source share