public override Data.Card Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var secondReader = reader; if (reader.TokenType != JsonTokenType.StartObject) { throw new JsonException("A Command object should start here"); } while (reader.TokenType != JsonTokenType.EndObject) { reader.Read(); // Going into the next field if (reader.TokenType != JsonTokenType.PropertyName) { throw new JsonException("A property should start here"); } var propName = reader.GetString(); // Reading the property name reader.Read(); // Going to the property value if (propName != "type") { continue; // We are searching for the property called "type" } if (reader.TokenType != JsonTokenType.String) { throw new JsonException("A \"type\" should be a string value"); } var value = reader.GetString(); if (value == Data.TextCard.TYPE) { Data.TextCard res = JsonSerializer.Deserialize <Data.TextCard>(ref secondReader, options); reader = secondReader; return(res); } else if (value == Data.ImageCard.TYPE) { Data.ImageCard res = JsonSerializer.Deserialize <Data.ImageCard>(ref secondReader, options); reader = secondReader; return(res); } else { throw new JsonException("A \"type\" should be either \"" + Data.TextCard.TYPE + "\" or \"" + Data.ImageCard.TYPE + "\""); } } throw new JsonException("JSON parser can't find the \"type\" property"); }
public UploadImageCardCommand(Data.ImageCard value) : base(TYPE) { this.Value = value; }