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/ConcreteRestrictedArrayJsonItem.cs

    r17473 r17481  
    99    public IEnumerable<T> ConcreteRestrictedItems { get; set; }
    1010
    11     protected override bool Validate() {
     11    protected override ValidationResult Validate() {
    1212      bool res = true;
     13      IList<string> errors = new List<string>();
    1314      foreach(var x in Value) {
    1415        bool tmp = false;
     
    1617          tmp = tmp || x.Equals(restrictedItem); //if one tmp is true, it stays true (match found)
    1718        }
     19        if (!tmp)
     20          errors.Add($"[{Path}]: Value '{x}' is not one of the allowed values: " +
     21                     $"'{ string.Join(",", ConcreteRestrictedItems.Select(s => s.ToString()).ToArray()) }'.");
    1822        res = res && tmp; //if one tmp is false, res will set false
    1923      }
    20       return res;
     24      if (res)
     25        return ValidationResult.Successful();
     26      else
     27        return ValidationResult.Faulty(errors);
    2128    }
    2229  }
Note: See TracChangeset for help on using the changeset viewer.