Skip to content

Commit

Permalink
Merge pull request #1878 from cwensley/curtis/json-key-converter
Browse files Browse the repository at this point in the history
Update TypeConverterConverter to use sc.TypeConverter for reading json
  • Loading branch information
cwensley authored Jan 13, 2021
2 parents 497d5fc + 93d37b7 commit e879620
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Eto.Serialization.Json/Converters/TypeConverterConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, TypeConverter> converters = new Dictionary<Type, TypeConverter>();
#pragma warning restore 618
readonly Dictionary<Type, sc.TypeConverter> converters = new Dictionary<Type, sc.TypeConverter>();

public override bool CanRead { get { return true; } }
public override bool CanWrite { get { return false; } }
Expand Down Expand Up @@ -56,21 +54,19 @@ 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);
return converter;
}
return null;
}
#pragma warning restore 618

public override bool CanConvert(Type objectType)
{
Expand Down
6 changes: 6 additions & 0 deletions test/Eto.Test/Sections/Serialization/Json/Test.jeto
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e879620

Please sign in to comment.