jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

unable to validate multiple condition in AssertThat validation #191

Open makwana8055 opened 5 years ago

makwana8055 commented 5 years ago
    [Display(ResourceType = (typeof(DisplayNamesForWeb)), Name = "SuggestedRequest")]
    public decimal? Amount1 { get; set; }

    [Display(ResourceType = (typeof(DisplayNamesForWeb)), Name = "OriginalRequest")]
    [AssertThat(@"Amount1 != null && Amount2 != null  && Amount2 <= Amount1", ErrorMessageResourceType = typeof(ErrorMessagesForWeb), ErrorMessageResourceName = "Amount2 must be less than or equal to Amount1")]
    public decimal? Amount2 { get; set; }
karim-ting commented 4 years ago

why not use separate assert annotations and give them different priority values as required?

tempel3 commented 4 years ago

"Amount1 == null || Amount2 == null || Amount2 <= Amount1" that should do it. It Amount1 hat no value -> true, if Amount2 has not value -> true and it Amount2 <= Amount1 -> true.

That way it will only check if Amount1 and Amount2 are set.

Is it what you need?