mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Smaller JSON fixes
This commit is contained in:
parent
137e9e73d1
commit
64c2780a6f
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
@ -19,7 +17,7 @@ namespace Wabbajack.Common
|
||||
{
|
||||
new HashJsonConverter(),
|
||||
new RelativePathConverter(),
|
||||
new AbolutePathConverter(),
|
||||
new AbsolutePathConverter(),
|
||||
new HashRelativePathConverter(),
|
||||
new FullPathConverter(),
|
||||
new GameConverter(),
|
||||
@ -33,7 +31,7 @@ namespace Wabbajack.Common
|
||||
Converters = Converters};
|
||||
|
||||
public static JsonSerializerSettings GenericJsonSettings =>
|
||||
new JsonSerializerSettings { };
|
||||
new JsonSerializerSettings();
|
||||
|
||||
|
||||
public static void ToJson<T>(this T obj, string filename)
|
||||
@ -62,16 +60,12 @@ namespace Wabbajack.Common
|
||||
return JsonConvert.SerializeObject(obj, JsonSettings);
|
||||
}
|
||||
|
||||
public static T FromJson<T>(this AbsolutePath filename,
|
||||
TypeNameHandling handling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormatHandling format = TypeNameAssemblyFormatHandling.Full)
|
||||
public static T FromJson<T>(this AbsolutePath filename)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(filename.ReadAllText(), JsonSettings)!;
|
||||
}
|
||||
|
||||
public static T FromJsonString<T>(this string data,
|
||||
TypeNameHandling handling = TypeNameHandling.Objects,
|
||||
TypeNameAssemblyFormatHandling format = TypeNameAssemblyFormatHandling.Full)
|
||||
public static T FromJsonString<T>(this string data)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(data, JsonSettings)!;
|
||||
}
|
||||
@ -116,7 +110,7 @@ namespace Wabbajack.Common
|
||||
}
|
||||
}
|
||||
|
||||
private class AbolutePathConverter : JsonConverter<AbsolutePath>
|
||||
private class AbsolutePathConverter : JsonConverter<AbsolutePath>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, AbsolutePath value, JsonSerializer serializer)
|
||||
{
|
||||
@ -246,11 +240,11 @@ namespace Wabbajack.Common
|
||||
{
|
||||
private static Dictionary<string, Type> _nameToType = new Dictionary<string, Type>();
|
||||
private static Dictionary<Type, string> _typeToName = new Dictionary<Type, string>();
|
||||
private static bool _inited = false;
|
||||
private static bool _init;
|
||||
|
||||
public JsonNameSerializationBinder()
|
||||
{
|
||||
if (_inited)
|
||||
if (_init)
|
||||
return;
|
||||
|
||||
var customDisplayNameTypes =
|
||||
@ -280,7 +274,7 @@ namespace Wabbajack.Common
|
||||
_typeToName = _nameToType.ToDictionary(
|
||||
t => t.Value,
|
||||
t => t.Key);
|
||||
_inited = true;
|
||||
_init = true;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user