42 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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());
 | 
						|
    }
 | 
						|
}
 |