| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | | using ValidateLib.Metadata.Properties; |
| | 5 | |
|
| | 6 | | namespace ValidateLib.Metadata.Parsers |
| | 7 | | { |
| | 8 | | public class ArrayPropertyParser<T> where T : DescriptorBase, Descriptors.Interfaces.IParsable<T> |
| | 9 | | { |
| 1 | 10 | | public ArrayProperty<T> Value { get; set; } = new ArrayProperty<T>(new List<T>()); |
| 1 | 11 | | public List<Warning> Warnings { get; set; } |
| | 12 | |
|
| 1 | 13 | | public ArrayPropertyParser(List<Warning> warnings, ArrayProperty<T>? descriptor = null) |
| | 14 | | { |
| 1 | 15 | | if (descriptor != null) Value = descriptor; |
| 1 | 16 | | Warnings = warnings; |
| 1 | 17 | | } |
| | 18 | | public ArrayProperty<T> ParseJToken(JProperty property) |
| | 19 | | { |
| 1 | 20 | | if (property.Value.Type != JTokenType.Array) |
| | 21 | | { |
| 1 | 22 | | Warnings.Add(WarningFactory.GetArrayPropertyWrongValueWarning(property, property.Value.Type.ToString())) |
| 1 | 23 | | return Value; |
| | 24 | | } |
| | 25 | | else |
| | 26 | | { |
| | 27 | |
|
| 1 | 28 | | foreach (var item in (JArray)property.Value) |
| | 29 | | { |
| 1 | 30 | | var TParser = T.GetParser(Warnings); |
| 1 | 31 | | var TObject = TParser.ParseJToken(item, property.Name); |
| 1 | 32 | | if (!TObject.IsInvalid) Value.AddItem(TObject); |
| | 33 | |
|
| | 34 | | } |
| | 35 | |
|
| 1 | 36 | | return Value; |
| | 37 | | } |
| | 38 | | } |
| | 39 | | } |
| | 40 | | } |