using System; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; namespace Syntriax.Engine.Core.Serialization; public class Projection1DSerializer : IEngineTypeYamlSerializer { public bool Accepts(Type type) => type == typeof(Projection1D); public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { parser.Consume(); if (parser.Consume().Value.CompareTo(nameof(Projection1D.Min)) != 0) throw new ArgumentException($"{nameof(Projection1D)} mapping must start with {nameof(Projection1D.Min)}"); float min = (float)rootDeserializer(typeof(float))!; if (parser.Consume().Value.CompareTo(nameof(Projection1D.Max)) != 0) throw new ArgumentException($"{nameof(Projection1D)} mapping must end with {nameof(Projection1D.Max)}"); float max = (float)rootDeserializer(typeof(float))!; parser.Consume(); return new Projection1D(min, max); } public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { Projection1D projection1D = (Projection1D)value!; emitter.Emit(new MappingStart()); emitter.Emit(new Scalar(nameof(Projection1D.Min))); serializer(projection1D.Min, typeof(float)); emitter.Emit(new Scalar(nameof(Projection1D.Max))); serializer(projection1D.Max, typeof(float)); emitter.Emit(new MappingEnd()); } }