using System; using System.Collections.Generic; using Engine.Serialization.DTOs; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; namespace Engine.Serialization; public class BehaviourDTOListConverter : IYamlTypeConverter { public bool Accepts(Type type) { return type == typeof(List); } public object ReadYaml(IParser parser, Type type) { var behaviours = new List(); if (parser.Current is SequenceStart) { parser.MoveNext(); while (parser.Current != null && !(parser.Current is SequenceEnd)) { behaviours.Add((BehaviourDTO)new BehaviourYamlConverter().ReadYaml(parser, typeof(BehaviourDTO))); parser.MoveNext(); } } return behaviours; } public void WriteYaml(IEmitter emitter, object? value, Type type) { var behaviours = (List)(value ?? throw new Exception()); emitter.Emit(new SequenceStart(null, null, false, SequenceStyle.Block)); foreach (var behaviour in behaviours) new BehaviourYamlConverter().WriteYaml(emitter, behaviour, typeof(BehaviourDTO)); emitter.Emit(new SequenceEnd()); } }