40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using ln.type;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ln.objects.serialization
|
|
{
|
|
public delegate bool LookupObjectByReference(object reference, Type objectType, out object o);
|
|
|
|
public abstract class Deserializer
|
|
{
|
|
public event LookupObjectByReference OnLookupObjectByReference;
|
|
|
|
public abstract bool DeserializeObject(byte[] serializedBytes, ref object o);
|
|
|
|
public bool TryLookupObject(object reference, Type targetType, out object o)
|
|
{
|
|
foreach (LookupObjectByReference lo in OnLookupObjectByReference?.GetInvocationList() ?? new LookupObjectByReference[0])
|
|
{
|
|
if (lo(reference, targetType, out o))
|
|
return true;
|
|
}
|
|
o = null;
|
|
return false;
|
|
}
|
|
|
|
public virtual bool TryGetType(byte[] serializedBytes,out Type type)
|
|
{
|
|
object o = null;
|
|
if (DeserializeObject(serializedBytes,ref o) && (!object.ReferenceEquals(null,o)))
|
|
{
|
|
type = o.GetType();
|
|
return true;
|
|
}
|
|
type = null;
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|