Last change
on this file since 17481 was
17481,
checked in by dpiringe, 4 years ago
|
#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 size:
826 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.JsonInterface {
|
---|
8 | public abstract class ConcreteRestrictedValueJsonItem<T> : ValueJsonItem<T>, IConcreteRestrictedJsonItem<T> {
|
---|
9 | public IEnumerable<T> ConcreteRestrictedItems { get; set; }
|
---|
10 |
|
---|
11 | protected override ValidationResult Validate() {
|
---|
12 | if (ConcreteRestrictedItems == null) return ValidationResult.Successful();
|
---|
13 | foreach (var x in ConcreteRestrictedItems)
|
---|
14 | if (Value.Equals(x)) return ValidationResult.Successful();
|
---|
15 | return ValidationResult.Faulty(
|
---|
16 | $"[{Path}]: Value {Value} is not one of the allowed values: " +
|
---|
17 | $"'{ string.Join(",", ConcreteRestrictedItems.Select(s => s.ToString()).ToArray()) }'.");
|
---|
18 | }
|
---|
19 | }
|
---|
20 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.