Last change
on this file since 18055 was
18055,
checked in by dpiringe, 3 years ago
|
#3026
- added StorableTypeAttribute and StorableConstructorAttribute to all JsonItems
- added a new JsonItem ListJsonItem + Interfaces IListJsonItem
- renamed SymRegPythonProcessor to RunCollectionSRSolutionPythonFormatter
- removed Interface IResultCollectionProcessor -> using the interface IRunCollectionModifier now (has aleady implementations)
- renamed all related variables/fields/properties with a connection to ResultCollectionProcessor
- added new implementations for IRunCollectionModifier
|
File size:
1.4 KB
|
Line | |
---|
1 | using System.Collections.Generic;
|
---|
2 | using System.Linq;
|
---|
3 | using HEAL.Attic;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.JsonInterface {
|
---|
6 | [StorableType("4333B6C0-26F7-41BA-A297-071AB50307F9")]
|
---|
7 | public abstract class ConcreteRestrictedArrayJsonItem<T> : ArrayJsonItem<T>, IConcreteRestrictedJsonItem<T> {
|
---|
8 | public IEnumerable<T> ConcreteRestrictedItems { get; set; }
|
---|
9 |
|
---|
10 | protected override ValidationResult Validate() {
|
---|
11 | bool res = true;
|
---|
12 | IList<string> errors = new List<string>();
|
---|
13 | if (ConcreteRestrictedItems == null) return ValidationResult.Successful();
|
---|
14 | foreach (var x in Value) {
|
---|
15 | bool tmp = false;
|
---|
16 | foreach (var restrictedItem in ConcreteRestrictedItems) {
|
---|
17 | tmp = tmp || x.Equals(restrictedItem); //if one tmp is true, it stays true (match found)
|
---|
18 | }
|
---|
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()) }'.");
|
---|
22 | res = res && tmp; //if one tmp is false, res will set false
|
---|
23 | }
|
---|
24 | if (res)
|
---|
25 | return ValidationResult.Successful();
|
---|
26 | else
|
---|
27 | return ValidationResult.Faulty(errors);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public ConcreteRestrictedArrayJsonItem() { }
|
---|
31 |
|
---|
32 | [StorableConstructor]
|
---|
33 | protected ConcreteRestrictedArrayJsonItem(StorableConstructorFlag _) : base(_) { }
|
---|
34 | }
|
---|
35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.