| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Errors; |
| | 3 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 4 | | using ValidateLib.Metadata.Descriptors; |
| | 5 | | using ValidateLib.Metadata.Descriptors.Interfaces; |
| | 6 | |
|
| | 7 | | namespace ValidateLib.Metadata.Parsers |
| | 8 | | { |
| | 9 | | internal class ForeignKeyParser : DescriptorParserBase<ForeignKeyDescriptor>, IParser<ForeignKeyDescriptor> |
| | 10 | | { |
| 1 | 11 | | public ForeignKeyParser(List<Warning> warnings, ForeignKeyDescriptor? descriptor = null) : base(warnings, descri |
| | 12 | | { |
| 1 | 13 | | } |
| | 14 | |
|
| | 15 | | new public ForeignKeyDescriptor ParseJToken(JToken jToken, string propertyName) |
| | 16 | | { |
| 1 | 17 | | if (jToken.Type != JTokenType.Object) |
| | 18 | | { |
| 1 | 19 | | if (jToken.Type == JTokenType.String) |
| 0 | 20 | | Warnings.Add(WarningFactory.GetObjectStringNormalizationProblemWarning(jToken.ToString(), propertyNa |
| | 21 | | else |
| 1 | 22 | | Warnings.Add(WarningFactory.GetObjectPropertyWrongValueWarning(jToken, propertyName)); |
| 1 | 23 | | Descriptor.IsInvalid = true; |
| 1 | 24 | | return Descriptor; |
| | 25 | | } |
| | 26 | | else |
| | 27 | | { |
| 1 | 28 | | foreach (JProperty property in jToken) |
| | 29 | | { |
| 1 | 30 | | var propertyParser = Descriptor.GetPropertyParser(property, Warnings); |
| 1 | 31 | | if (propertyParser == null) |
| | 32 | | { |
| 1 | 33 | | ErrorFactory.ThrowInvalidPropertyOnFKDescriptorError(property.ToString()); |
| | 34 | | } |
| | 35 | | else |
| | 36 | | { |
| 1 | 37 | | propertyParser.ParseProperty(property); |
| | 38 | | } |
| | 39 | | } |
| 1 | 40 | | if (Descriptor is IRequiredPropertyValidatable) ((IRequiredPropertyValidatable)Descriptor).CheckRequired |
| 1 | 41 | | return Descriptor; |
| | 42 | | } |
| | 43 | | } |
| | 44 | | } |
| | 45 | | } |