internal static Restriction DeserializeRestriction(JsonElement element) { string type = default; IReadOnlyList <string> values = default; ReasonCode? reasonCode = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } type = property.Value.GetString(); continue; } if (property.NameEquals("values")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(item.GetString()); } } values = array; continue; } if (property.NameEquals("reasonCode")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } reasonCode = new ReasonCode(property.Value.GetString()); continue; } } return(new Restriction(type, values, reasonCode)); }
internal static Restriction DeserializeRestriction(JsonElement element) { Optional <string> type = default; Optional <IReadOnlyList <string> > values = default; Optional <ReasonCode> reasonCode = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("values")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } values = array; continue; } if (property.NameEquals("reasonCode")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } reasonCode = new ReasonCode(property.Value.GetString()); continue; } } return(new Restriction(type.Value, Optional.ToList(values), Optional.ToNullable(reasonCode))); }