| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | | using ValidateLib.Metadata.Descriptors.Interfaces; |
| | 5 | |
|
| | 6 | | namespace ValidateLib.Metadata.Properties |
| | 7 | | { |
| | 8 | | public class ArrayProperty<T> : Property<List<T>>, INormalize |
| | 9 | | { |
| 1 | 10 | | public ArrayProperty(List<T> value) : base(value) |
| | 11 | | { |
| | 12 | |
|
| 1 | 13 | | } |
| | 14 | |
|
| | 15 | | public void AddItem(T item) |
| | 16 | | { |
| 1 | 17 | | if (_value is null) _value = new List<T>(); |
| 1 | 18 | | _value.Add(item); |
| 1 | 19 | | } |
| | 20 | |
|
| | 21 | |
|
| | 22 | | public static ArrayProperty<string> CreateStringArrayPropertyFromJToken(JToken token) |
| | 23 | | { |
| 0 | 24 | | List<string> list = new List<string>(); |
| 0 | 25 | | if (token.Type != JTokenType.Array) throw new ArgumentException(); |
| 0 | 26 | | foreach (var item in token) |
| | 27 | | { |
| 0 | 28 | | list.Add(item.ToString()); |
| | 29 | | } |
| 0 | 30 | | return new ArrayProperty<string>(list); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public static List<Warning> Normalize<T2>(JToken token, Context context, JProperty? property = null) where T2 : |
| | 34 | | { |
| 1 | 35 | | List<Warning> errors = new List<Warning>(); |
| 1 | 36 | | if (token.Type != JTokenType.Array) return errors; |
| 1 | 37 | | foreach (var item in (JArray)token) |
| | 38 | | { |
| 1 | 39 | | var results = T2.Normalize(item, context, property); |
| | 40 | | } |
| 1 | 41 | | return errors; |
| | 42 | | } |
| | 43 | | static List<Warning> INormalize.Normalize(JToken token, Context context, JProperty? prop) |
| | 44 | | { |
| 0 | 45 | | throw new NotImplementedException(); |
| | 46 | | } |
| | 47 | |
|
| | 48 | | } |
| | 49 | | } |