forked from ImaginaryDevelopment/imaginary-hero-designer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyApplication.cs
37 lines (34 loc) · 1.25 KB
/
MyApplication.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using Newtonsoft.Json;
namespace Hero_Designer.My
{
internal class MyApplication
{
public class Serializer : ISerialize
{
readonly Func<object, string> _serializeFunc;
public string Extension { get; }
public Serializer(Func<object, string> serializeFunc, string extension)
{
Extension = extension;
_serializeFunc = serializeFunc;
}
public string Serialize(object o) => _serializeFunc(o);
public T Deserialize<T>(string x) => JsonConvert.DeserializeObject<T>(x);
}
public static ISerialize GetSerializer()
{
return new Serializer(x =>
JsonConvert.SerializeObject(x,
Formatting.Indented
, settings: new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.None,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
}
), "json");
}
}
}