Fix JSON read/write, XML write

This commit is contained in:
Matt Nadareski
2020-08-24 11:56:49 -07:00
parent a424f53407
commit d8fdce88c0
26 changed files with 348 additions and 2064 deletions

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace SabreTools.Library.Tools
{
// https://github.com/dotnet/runtime/issues/728
public class BaseFirstContractResolver : DefaultContractResolver
{
public BaseFirstContractResolver()
{
NamingStrategy = new CamelCaseNamingStrategy();
}
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
return base.CreateProperties(type, memberSerialization)
.OrderBy(p => BaseTypesAndSelf(p.DeclaringType).Count()).ToList();
IEnumerable<Type> BaseTypesAndSelf(Type t)
{
while (t != null)
{
yield return t;
t = t.BaseType;
}
}
}
}
}