private static JsonElement GetJsonElement(ClipboardEventArgs args) { var json = JsonSerializer.SerializeToUtf8Bytes(args, JsonSerializerOptionsProvider.Options); var jsonReader = new Utf8JsonReader(json); var jsonElement = JsonElement.ParseValue(ref jsonReader); return(jsonElement); }
public void Read_Works() { // Arrange var args = new ClipboardEventArgs { Type = "Some type" }; var jsonElement = GetJsonElement(args); // Act var result = ClipboardEventArgsReader.Read(jsonElement); // Assert Assert.Equal(args.Type, result.Type); }
internal static ClipboardEventArgs Read(JsonElement jsonElement) { var eventArgs = new ClipboardEventArgs(); foreach (var property in jsonElement.EnumerateObject()) { if (property.NameEquals(TypeKey.EncodedUtf8Bytes)) { eventArgs.Type = property.Value.GetString() !; } else { throw new JsonException($"Unknown property {property.Name}"); } } return(eventArgs); }