public override IDrawable Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.StartObject) { throw new JsonException(); } reader.Read(); if (reader.TokenType != JsonTokenType.PropertyName) { throw new JsonException(); } string propertyName = reader.GetString(); if (propertyName != "$type") { throw new JsonException(); } reader.Read(); if (reader.TokenType != JsonTokenType.String) { throw new JsonException(); } var typeDiscriminator = reader.GetString(); IDrawable drawable; if (typeDiscriminator == GetDiscriminator(typeof(InkDrawable)) || typeDiscriminator == OldInkDrawableDiscriminator) { drawable = new InkDrawable(); } else if (typeDiscriminator == GetDiscriminator(typeof(TextDrawable)) || typeDiscriminator == OldTextDrawableDiscriminator) { drawable = new TextDrawable(); } else { throw new JsonException(); } while (reader.Read()) { if (reader.TokenType == JsonTokenType.EndObject) { drawable.OnDeserialized(); return(drawable); } if (reader.TokenType == JsonTokenType.PropertyName) { propertyName = reader.GetString(); reader.Read(); switch (propertyName) { case "IsActive": drawable.IsActive = reader.GetBoolean(); break; case "Bounds": drawable.Bounds = JsonSerializer.Deserialize <Rect>(ref reader); break; default: drawable.ReadProperty(propertyName, ref reader); break; } } } throw new JsonException(); }
public InfiniteCanvasCreateInkCommand(List <IDrawable> drawableList, IReadOnlyList <InkStroke> strokes) { _drawable = new InkDrawable(strokes); _drawableList = drawableList; }