mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 07:12:27 +02:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Robust.Shared.Serialization.Manager.Result
|
|
{
|
|
public sealed class DeserializedDefinition<T> : DeserializationResult<T>, IDeserializedDefinition where T : notnull, new()
|
|
{
|
|
public DeserializedDefinition(T value, DeserializedFieldEntry[] mapping)
|
|
{
|
|
Value = value;
|
|
Mapping = mapping;
|
|
}
|
|
|
|
public override T Value { get; }
|
|
|
|
public DeserializedFieldEntry[] Mapping { get; }
|
|
|
|
public override object RawValue => Value;
|
|
|
|
public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
|
|
{
|
|
var dataDef = source.Cast<DeserializedDefinition<T>>();
|
|
if (dataDef.Mapping.Length != Mapping.Length)
|
|
throw new ArgumentException($"Mapping length mismatch in PushInheritanceFrom ({typeof(T)})");
|
|
|
|
var newMapping = new DeserializedFieldEntry[Mapping.Length];
|
|
|
|
for (var i = 0; i < dataDef.Mapping.Length; i++)
|
|
{
|
|
newMapping[i] = Mapping[i].PushInheritanceFrom(dataDef.Mapping[i]);
|
|
}
|
|
|
|
return IoCManager.Resolve<ISerializationManager>().CreateDataDefinition<T>(newMapping, true);
|
|
}
|
|
|
|
public override DeserializationResult Copy()
|
|
{
|
|
var newMapping = new DeserializedFieldEntry[Mapping.Length];
|
|
|
|
for (var i = 0; i < Mapping.Length; i++)
|
|
{
|
|
newMapping[i] = Mapping[i].Copy();
|
|
}
|
|
|
|
return IoCManager.Resolve<ISerializationManager>().CreateDataDefinition<T>(newMapping, true);
|
|
}
|
|
|
|
public override void CallAfterDeserializationHook()
|
|
{
|
|
foreach (var fieldEntry in Mapping)
|
|
{
|
|
fieldEntry.Result?.CallAfterDeserializationHook();
|
|
}
|
|
|
|
if (Value is ISerializationHooks hooks)
|
|
hooks.AfterDeserialization();
|
|
}
|
|
}
|
|
}
|