using System; using System.Collections.Generic; using Robust.Shared.Serialization.Manager.Result; using Robust.Shared.Serialization.Markdown; using Robust.Shared.Serialization.Markdown.Validation; using Robust.Shared.Serialization.TypeSerializers.Interfaces; namespace Robust.Shared.Serialization.Manager { public partial class SerializationManager { private readonly Dictionary _customTypeSerializers = new(); private DeserializationResult ReadWithSerializer( TNode node, ISerializationContext? context = null, bool skipHook = false) where TSerializer : ITypeReader where T : notnull where TNode : DataNode { var serializer = (ITypeReader)GetTypeSerializer(typeof(TSerializer)); return serializer.Read(this, node, DependencyCollection, skipHook, context); } private DataNode WriteWithSerializer( T value, ISerializationContext? context = null, bool alwaysWrite = false) where TSerializer : ITypeWriter where T : notnull { var serializer = (ITypeWriter)GetTypeSerializer(typeof(TSerializer)); return serializer.Write(this, value, alwaysWrite, context); } private TCommon CopyWithSerializer( TSource source, TTarget target, bool skipHook, ISerializationContext? context = null) where TSource : TCommon where TTarget : TCommon where TCommon : notnull where TSerializer : ITypeCopier { var serializer = (ITypeCopier) GetTypeSerializer(typeof(TSerializer)); return serializer.Copy(this, source, target, skipHook, context); } private ValidationNode ValidateWithSerializer( TNode node, ISerializationContext? context) where T : notnull where TNode : DataNode where TSerializer : ITypeValidator { var serializer = (ITypeValidator) GetTypeSerializer(typeof(TSerializer)); return serializer.Validate(this, node, DependencyCollection, context); } } }