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 Line2DEquationConverter : EngineTypeYamlSerializerBase<Line2DEquation>
|
||||
{
|
||||
public override Line2DEquation Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
parser.Consume<MappingStart>();
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Line2DEquation.Slope)) != 0)
|
||||
throw new ArgumentException($"{nameof(Line2DEquation)} mapping must start with {nameof(Line2DEquation.Slope)}");
|
||||
float slope = (float)rootDeserializer(typeof(float))!;
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Line2DEquation.OffsetY)) != 0)
|
||||
throw new ArgumentException($"{nameof(Line2DEquation)} mapping must end with {nameof(Line2DEquation.OffsetY)}");
|
||||
float offset = (float)rootDeserializer(typeof(float))!;
|
||||
|
||||
parser.Consume<MappingEnd>();
|
||||
|
||||
return new Line2DEquation(slope, offset);
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Line2DEquation line2DEquation = (Line2DEquation)value!;
|
||||
|
||||
emitter.Emit(new MappingStart());
|
||||
emitter.Emit(new Scalar(nameof(Line2DEquation.Slope)));
|
||||
serializer(line2DEquation.Slope, typeof(float));
|
||||
emitter.Emit(new Scalar(nameof(Line2DEquation.OffsetY)));
|
||||
serializer(line2DEquation.OffsetY, typeof(float));
|
||||
emitter.Emit(new MappingEnd());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user