2020-02-27 18:56:49 +01:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
namespace MLEM.Data.Json {
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// A helper class that stores all of the <see cref="JsonConverter"/> types that are part of MLEM.Data.
|
|
|
|
/// </summary>
|
2020-02-27 18:56:49 +01:00
|
|
|
public class JsonConverters {
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// An array of all of the <see cref="JsonConverter"/>s that are part of MLEM.Data
|
|
|
|
/// </summary>
|
2020-02-27 19:43:36 +01:00
|
|
|
public static readonly JsonConverter[] Converters = typeof(JsonConverters).Assembly.GetExportedTypes()
|
2021-03-13 03:15:39 +01:00
|
|
|
.Where(t => t.IsSubclassOf(typeof(JsonConverter)) && !t.IsGenericType)
|
2021-10-28 22:14:43 +02:00
|
|
|
.Select(Activator.CreateInstance).Cast<JsonConverter>().ToArray();
|
2020-02-27 18:56:49 +01:00
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Adds all of the <see cref="JsonConverter"/> objects that are part of MLEM.Data to the given <see cref="JsonSerializer"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="serializer">The serializer to add the converters to</param>
|
|
|
|
/// <returns>The given serializer, for chaining</returns>
|
2020-02-27 18:56:49 +01:00
|
|
|
public static JsonSerializer AddAll(JsonSerializer serializer) {
|
|
|
|
foreach (var converter in Converters)
|
|
|
|
serializer.Converters.Add(converter);
|
|
|
|
return serializer;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|