BREAKING CHANGE: moved yaml serialization from Engine.Serialization to Engine.Integration
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Projection1DConverter : EngineTypeYamlSerializerBase<Projection1D>
|
||||
{
|
||||
public override Projection1D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
parser.Consume<MappingStart>();
|
||||
|
||||
if (parser.Consume<Scalar>().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<Scalar>().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<MappingEnd>();
|
||||
|
||||
return new Projection1D(min, max);
|
||||
}
|
||||
|
||||
public override 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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user