From 93d37b7c017e78d3bb2f9dd6f33f3d463327e1a2 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Tue, 12 Jan 2021 23:23:44 -0800 Subject: [PATCH] Update TypeConverterConverter to use sc.TypeConverter for reading json Fixes #1866 --- .../Converters/TypeConverterConverter.cs | 14 +++++--------- .../Eto.Test/Sections/Serialization/Json/Test.jeto | 6 ++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Eto.Serialization.Json/Converters/TypeConverterConverter.cs b/src/Eto.Serialization.Json/Converters/TypeConverterConverter.cs index 6916c81695..0b64bad177 100644 --- a/src/Eto.Serialization.Json/Converters/TypeConverterConverter.cs +++ b/src/Eto.Serialization.Json/Converters/TypeConverterConverter.cs @@ -2,16 +2,14 @@ using Newtonsoft.Json; using System.Reflection; using System.Collections.Generic; -using System.ComponentModel; +using sc = System.ComponentModel; using Newtonsoft.Json.Linq; namespace Eto.Serialization.Json.Converters { public class TypeConverterConverter : JsonConverter { -#pragma warning disable 618 - readonly Dictionary converters = new Dictionary(); -#pragma warning restore 618 + readonly Dictionary converters = new Dictionary(); public override bool CanRead { get { return true; } } public override bool CanWrite { get { return false; } } @@ -56,13 +54,12 @@ public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectTy return reader.Value; } -#pragma warning disable 618 - TypeConverter GetConverter(Type objectType, Type destinationType) + sc.TypeConverter GetConverter(Type objectType, Type destinationType) { - TypeConverter converter; + sc.TypeConverter converter; if (converters.TryGetValue(objectType, out converter)) return converter; - converter = TypeDescriptor.GetConverter(objectType); + converter = sc.TypeDescriptor.GetConverter(objectType); if (converter != null && converter.CanConvertFrom(destinationType)) { converters.Add(objectType, converter); @@ -70,7 +67,6 @@ TypeConverter GetConverter(Type objectType, Type destinationType) } return null; } -#pragma warning restore 618 public override bool CanConvert(Type objectType) { diff --git a/test/Eto.Test/Sections/Serialization/Json/Test.jeto b/test/Eto.Test/Sections/Serialization/Json/Test.jeto index dc18432e53..daf4e680ab 100644 --- a/test/Eto.Test/Sections/Serialization/Json/Test.jeto +++ b/test/Eto.Test/Sections/Serialization/Json/Test.jeto @@ -5,6 +5,12 @@ Pages: [ { Text: "Table Layout", + ContextMenu: { + $type: "ContextMenu", + Items: [ + { "$type": "ButtonMenuItem", "Text": "Some Item", "Shortcut": "CommonModifier+P", "Click": "HandleButtonClick" } + ] + }, Content: { $type: "TableLayout", Padding: "10",