using System; using Newtonsoft.Json; namespace MLEM.Data.Json { /// /// Converts a to and from JSON /// [Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))] public class DynamicEnumConverter : JsonConverter { /// Writes the JSON representation of the object. /// The to write to. /// The value. /// The calling serializer. public override void WriteJson(JsonWriter writer, DynamicEnum value, JsonSerializer serializer) { writer.WriteValue(value.ToString()); } /// Reads the JSON representation of the object. /// The to read from. /// Type of the object. /// The existing value of object being read. If there is no existing value then null will be used. /// The existing value has a value. /// The calling serializer. /// The object value. public override DynamicEnum ReadJson(JsonReader reader, Type objectType, DynamicEnum existingValue, bool hasExistingValue, JsonSerializer serializer) { return DynamicEnum.Parse(objectType, reader.Value.ToString()); } } }