mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-06-24 13:50:04 +02:00
20 lines
702 B
C#
20 lines
702 B
C#
|
using System;
|
||
|
using System.Linq;
|
||
|
using System.Reflection;
|
||
|
using Newtonsoft.Json;
|
||
|
|
||
|
namespace MLEM.Data.Json {
|
||
|
public class JsonConverters {
|
||
|
|
||
|
public static readonly JsonConverter[] Converters = Assembly.GetExecutingAssembly().GetExportedTypes()
|
||
|
.Where(t => t.Namespace == typeof(JsonConverters).Namespace && t.IsSubclassOf(typeof(JsonConverter)))
|
||
|
.Select(t => t.GetConstructor(Type.EmptyTypes).Invoke(null)).Cast<JsonConverter>().ToArray();
|
||
|
|
||
|
public static JsonSerializer AddAll(JsonSerializer serializer) {
|
||
|
foreach (var converter in Converters)
|
||
|
serializer.Converters.Add(converter);
|
||
|
return serializer;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|