chore: added a generic converter
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Factory;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Syntriax.Engine.Serialization;
|
||||
|
||||
public class EntityConverter : IEngineTypeYamlConverter
|
||||
{
|
||||
public bool Accepts(Type type) => typeof(IEntity).IsAssignableFrom(type);
|
||||
|
||||
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
EntityReference entityReference = (EntityReference)rootDeserializer(typeof(EntityReference))!;
|
||||
|
||||
IEntity entity = (IEntity)TypeFactory.Get(entityReference.TypeContainer.Type);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
IEntity? entity = (IEntity)value!;
|
||||
|
||||
serializer(new EntityReference(entity), typeof(EntityReference));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user