using System; using MLEM.Misc; using Newtonsoft.Json; namespace MLEM.Data.Json { /// /// Converts a to and from JSON /// public class Direction2Converter : JsonConverter { /// Writes the JSON representation of the object. /// The to write to. /// The value. /// The calling serializer. public override void WriteJson(JsonWriter writer, Direction2 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 Direction2 ReadJson(JsonReader reader, Type objectType, Direction2 existingValue, bool hasExistingValue, JsonSerializer serializer) { Enum.TryParse(reader.Value.ToString(), out var dir); return dir; } } }