mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-03 10:37:05 +02:00
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
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<Type, object> _customTypeSerializers = new();
|
|
|
|
private DeserializationResult ReadWithSerializer<T, TNode, TSerializer>(
|
|
TNode node,
|
|
ISerializationContext? context = null,
|
|
bool skipHook = false)
|
|
where TSerializer : ITypeReader<T, TNode>
|
|
where T : notnull
|
|
where TNode : DataNode
|
|
{
|
|
var serializer = (ITypeReader<T, TNode>)GetTypeSerializer(typeof(TSerializer));
|
|
return serializer.Read(this, node, DependencyCollection, skipHook, context);
|
|
}
|
|
|
|
private DataNode WriteWithSerializer<T, TSerializer>(
|
|
T value,
|
|
ISerializationContext? context = null,
|
|
bool alwaysWrite = false)
|
|
where TSerializer : ITypeWriter<T>
|
|
where T : notnull
|
|
{
|
|
var serializer = (ITypeWriter<T>)GetTypeSerializer(typeof(TSerializer));
|
|
return serializer.Write(this, value, alwaysWrite, context);
|
|
}
|
|
|
|
private TCommon CopyWithSerializer<TCommon, TSource, TTarget, TSerializer>(
|
|
TSource source,
|
|
TTarget target,
|
|
bool skipHook,
|
|
ISerializationContext? context = null)
|
|
where TSource : TCommon
|
|
where TTarget : TCommon
|
|
where TCommon : notnull
|
|
where TSerializer : ITypeCopier<TCommon>
|
|
{
|
|
var serializer = (ITypeCopier<TCommon>) GetTypeSerializer(typeof(TSerializer));
|
|
return serializer.Copy(this, source, target, skipHook, context);
|
|
}
|
|
|
|
private ValidationNode ValidateWithSerializer<T, TNode, TSerializer>(
|
|
TNode node,
|
|
ISerializationContext? context)
|
|
where T : notnull
|
|
where TNode : DataNode
|
|
where TSerializer : ITypeValidator<T, TNode>
|
|
{
|
|
var serializer = (ITypeValidator<T, TNode>) GetTypeSerializer(typeof(TSerializer));
|
|
return serializer.Validate(this, node, DependencyCollection, context);
|
|
}
|
|
}
|
|
}
|