コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }