Single-use class should be private

This commit is contained in:
Matt Nadareski
2020-12-09 00:42:22 -08:00
parent 9c51831c81
commit 0e1e79a4e8
2 changed files with 26 additions and 33 deletions

View File

@@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace SabreTools.Core
{
// 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;
}
}
}
}
}

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using SabreTools.Core; using SabreTools.Core;
@@ -8,6 +9,7 @@ using SabreTools.Core.Tools;
using SabreTools.DatItems; using SabreTools.DatItems;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
namespace SabreTools.DatFiles namespace SabreTools.DatFiles
{ {
@@ -520,5 +522,29 @@ namespace SabreTools.DatFiles
jtw.Flush(); jtw.Flush();
} }
// https://github.com/dotnet/runtime/issues/728
private 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;
}
}
}
}
} }
} }