Last change
on this file since 17530 was
17519,
checked in by dpiringe, 5 years ago
|
#3026:
- added error output for failed runner initialization
- reorganised some final view models
- TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
- code cleanup
- refactored RegressionProblemDataConverter
- added lots of comments
- added new view for StringArrayJsonItem
- added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
|
File size:
1.1 KB
|
Line | |
---|
1 | using System.Collections.Generic;
|
---|
2 | using System.Linq;
|
---|
3 | namespace HeuristicLab.JsonInterface {
|
---|
4 | public abstract class ConcreteRestrictedArrayJsonItem<T> : ArrayJsonItem<T>, IConcreteRestrictedJsonItem<T> {
|
---|
5 | public IEnumerable<T> ConcreteRestrictedItems { get; set; }
|
---|
6 |
|
---|
7 | protected override ValidationResult Validate() {
|
---|
8 | bool res = true;
|
---|
9 | IList<string> errors = new List<string>();
|
---|
10 | if (ConcreteRestrictedItems == null) return ValidationResult.Successful();
|
---|
11 | foreach(var x in Value) {
|
---|
12 | bool tmp = false;
|
---|
13 | foreach(var restrictedItem in ConcreteRestrictedItems) {
|
---|
14 | tmp = tmp || x.Equals(restrictedItem); //if one tmp is true, it stays true (match found)
|
---|
15 | }
|
---|
16 | if (!tmp)
|
---|
17 | errors.Add($"[{Path}]: Value '{x}' is not one of the allowed values: " +
|
---|
18 | $"'{ string.Join(",", ConcreteRestrictedItems.Select(s => s.ToString()).ToArray()) }'.");
|
---|
19 | res = res && tmp; //if one tmp is false, res will set false
|
---|
20 | }
|
---|
21 | if (res)
|
---|
22 | return ValidationResult.Successful();
|
---|
23 | else
|
---|
24 | return ValidationResult.Faulty(errors);
|
---|
25 | }
|
---|
26 | }
|
---|
27 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.