private static AvailableTransport ParseAvailableTransport(ref Utf8JsonReader reader) { var availableTransport = new AvailableTransport(); while (reader.CheckRead()) { switch (reader.TokenType) { case JsonTokenType.PropertyName: var memberName = reader.ValueSpan; if (memberName.SequenceEqual(TransportPropertyNameBytes)) { availableTransport.Transport = reader.ReadAsString(TransportPropertyNameBytes); } else if (memberName.SequenceEqual(TransferFormatsPropertyNameBytes)) { reader.CheckRead(); reader.EnsureArrayStart(); var completed = false; availableTransport.TransferFormats = new List <string>(); while (!completed && reader.CheckRead()) { switch (reader.TokenType) { case JsonTokenType.String: availableTransport.TransferFormats.Add(reader.GetString()); break; case JsonTokenType.EndArray: completed = true; break; default: throw new InvalidDataException($"Unexpected token '{reader.TokenType}' when reading transfer formats JSON."); } } } else { reader.Skip(); } break; case JsonTokenType.EndObject: if (availableTransport.Transport == null) { throw new InvalidDataException($"Missing required property '{TransportPropertyName}'."); } if (availableTransport.TransferFormats == null) { throw new InvalidDataException($"Missing required property '{TransferFormatsPropertyName}'."); } return(availableTransport); default: throw new InvalidDataException($"Unexpected token '{reader.TokenType}' when reading available transport JSON."); } } throw new InvalidDataException("Unexpected end when reading JSON."); }
private static AvailableTransport ParseAvailableTransport(JsonTextReader reader) { var availableTransport = new AvailableTransport(); while (JsonUtils.CheckRead(reader)) { switch (reader.TokenType) { case JsonToken.PropertyName: var memberName = reader.Value.ToString(); switch (memberName) { case TransportPropertyName: availableTransport.Transport = JsonUtils.ReadAsString(reader, TransportPropertyName); break; case TransferFormatsPropertyName: JsonUtils.CheckRead(reader); JsonUtils.EnsureArrayStart(reader); var completed = false; availableTransport.TransferFormats = new List <string>(); while (!completed && JsonUtils.CheckRead(reader)) { switch (reader.TokenType) { case JsonToken.String: availableTransport.TransferFormats.Add(reader.Value.ToString()); break; case JsonToken.EndArray: completed = true; break; default: throw new InvalidDataException($"Unexpected token '{reader.TokenType}' when reading transfer formats JSON."); } } break; default: reader.Skip(); break; } break; case JsonToken.EndObject: if (availableTransport.Transport == null) { throw new InvalidDataException($"Missing required property '{TransportPropertyName}'."); } if (availableTransport.TransferFormats == null) { throw new InvalidDataException($"Missing required property '{TransferFormatsPropertyName}'."); } return(availableTransport); default: throw new InvalidDataException($"Unexpected token '{reader.TokenType}' when reading available transport JSON."); } } throw new InvalidDataException("Unexpected end when reading JSON."); }