| | 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.AtomicProperties |
| | 7 | | { |
| | 8 | | public class AtomicPropertyArray<T> : AtomicProperty<List<T>>, INormalize |
| | 9 | | { |
| 1 | 10 | | public AtomicPropertyArray(List<T> value) : base(value) { } |
| | 11 | |
|
| | 12 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | 13 | | { |
| 0 | 14 | | List<Warning> warnings = new List<Warning>(); |
| 0 | 15 | | if (token.Type != JTokenType.Array) return warnings; |
| 0 | 16 | | else if (typeof(T) == typeof(string)) |
| | 17 | | { |
| 0 | 18 | | foreach (var item in token) |
| | 19 | | { |
| 0 | 20 | | if (item.Type != JTokenType.String) return warnings; |
| | 21 | | } |
| 0 | 22 | | return warnings; |
| | 23 | | } |
| 0 | 24 | | else if (typeof(T) == typeof(bool)) |
| | 25 | | { |
| | 26 | |
|
| 0 | 27 | | foreach (var item in token) |
| | 28 | | { |
| 0 | 29 | | if (item.Type != JTokenType.Boolean) return warnings; |
| | 30 | | } |
| 0 | 31 | | return warnings; |
| | 32 | | } |
| 0 | 33 | | else if (typeof(T) == typeof(int)) |
| | 34 | | { |
| | 35 | |
|
| 0 | 36 | | foreach (var item in token) |
| | 37 | | { |
| 0 | 38 | | if (item.Type != JTokenType.Integer) return warnings; |
| | 39 | | } |
| 0 | 40 | | return warnings; |
| | 41 | | } |
| 0 | 42 | | else if (typeof(T) == typeof(double)) |
| | 43 | | { |
| | 44 | |
|
| 0 | 45 | | foreach (var item in token) |
| | 46 | | { |
| 0 | 47 | | if (item.Type != JTokenType.Float) return warnings; |
| | 48 | | } |
| 0 | 49 | | return warnings; |
| | 50 | | } |
| | 51 | | else |
| | 52 | | { |
| 0 | 53 | | throw new NotImplementedException(); |
| | 54 | | } |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | |
|
| | 58 | |
|
| | 59 | | } |
| | 60 | | } |