Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/20 17:03:24 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • refactored json item validation process -> every method now returns a ValidationResult containing bool Success (true if validation is successful) and IEnumerable<string> Errors (error messages)
    • this design allows to specify error messages directly in json items
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntervalRestrictedArrayJsonItem.cs

    r17477 r17481  
    1212    public T Maximum { get; set; }
    1313
    14     protected override bool Validate() {
    15       foreach(var x in Value) {
    16         if (Minimum.CompareTo(x) > 0 || Maximum.CompareTo(x) < 0)
    17           return false;
     14    protected override ValidationResult Validate() {
     15      IList<string> errors = new List<string>();
     16      bool success = true;
     17      foreach (var x in Value) {
     18        if (Minimum.CompareTo(x) > 0 && Maximum.CompareTo(x) < 0) {
     19          success = false;
     20          errors.Add($"[{Path}]: Value {x} is not between {Minimum} and {Maximum}.");
     21        }
    1822      }
    19       return true;
     23      return new ValidationResult(success, errors);
    2024    }
    2125
Note: See TracChangeset for help on using the changeset viewer.