mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
|
|
namespace Robust.Shared.Serialization.Manager.Result
|
|
{
|
|
public sealed class DeserializedArray : DeserializationResult
|
|
{
|
|
public DeserializedArray(Array array, DeserializationResult[] mappings)
|
|
{
|
|
Value = array;
|
|
Mappings = mappings;
|
|
}
|
|
|
|
public Array Value { get; }
|
|
|
|
public DeserializationResult[] Mappings { get; }
|
|
|
|
public override object RawValue => Value;
|
|
|
|
public override DeserializationResult PushInheritanceFrom(DeserializationResult source)
|
|
{
|
|
var sourceCollection = source.Cast<DeserializedArray>();
|
|
var values = (Array) Activator.CreateInstance(Value.GetType(), Value.Length)!;
|
|
var results = new DeserializationResult[sourceCollection.Mappings.Length];
|
|
|
|
for (var i = 0; i < sourceCollection.Mappings.Length; i++)
|
|
{
|
|
var oldRes = sourceCollection.Mappings[i];
|
|
var newRes = oldRes.Copy();
|
|
|
|
values.SetValue(newRes.RawValue, i);
|
|
results[i] = newRes;
|
|
}
|
|
|
|
for (var i = 0; i < Mappings.Length; i++)
|
|
{
|
|
var oldRes = Mappings[i];
|
|
var newRes = oldRes.Copy();
|
|
|
|
values.SetValue(newRes.RawValue, i);
|
|
results[i] = newRes;
|
|
}
|
|
|
|
return new DeserializedArray(values, results);
|
|
}
|
|
|
|
public override DeserializationResult Copy()
|
|
{
|
|
var values = (Array) Activator.CreateInstance(Value.GetType(), Value.Length)!;
|
|
var results = new DeserializationResult[Mappings.Length];
|
|
|
|
for (var i = 0; i < Mappings.Length; i++)
|
|
{
|
|
var oldRes = Mappings[i];
|
|
var newRes = oldRes.Copy();
|
|
|
|
values.SetValue(newRes.RawValue, i);
|
|
results[i] = newRes;
|
|
}
|
|
|
|
return new DeserializedArray(values, results);
|
|
}
|
|
|
|
public override void CallAfterDeserializationHook()
|
|
{
|
|
foreach (var elem in Mappings)
|
|
{
|
|
elem.CallAfterDeserializationHook();
|
|
}
|
|
}
|
|
}
|
|
}
|