|
|
@ -46,6 +46,7 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private readonly static Dictionary<Type, Wrapper> _cachee = new Dictionary<Type, Wrapper>();
|
|
|
|
private readonly static Dictionary<Type, Wrapper> _cachee = new Dictionary<Type, Wrapper>();
|
|
|
|
private readonly static Dictionary<Type, Type> _enumTypesCachee = new Dictionary<Type, Type>();
|
|
|
|
private readonly static Dictionary<Type, Type> _enumTypesCachee = new Dictionary<Type, Type>();
|
|
|
|
|
|
|
|
private readonly static Dictionary<Type, Type> _arrayTypesCachee = new Dictionary<Type, Type>();
|
|
|
|
|
|
|
|
|
|
|
|
private static void PreloadCachee()
|
|
|
|
private static void PreloadCachee()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -69,6 +70,25 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
_cachee.Add(typeof(IPEndPoint), Create<IPEndPoint>());
|
|
|
|
_cachee.Add(typeof(IPEndPoint), Create<IPEndPoint>());
|
|
|
|
_cachee.Add(typeof(IPAddress), Create<IPAddress>());
|
|
|
|
_cachee.Add(typeof(IPAddress), Create<IPAddress>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_cachee.Add(typeof(char[]), Create<char[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Boolean[]), Create<Boolean[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Byte[][]), Create<Byte[][]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Int32[]), Create<Int32[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(UInt32[]), Create<UInt32[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Int64[]), Create<Int64[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(UInt64[]), Create<UInt64[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Double[]), Create<Double[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(float[]), Create<float[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(short[]), Create<short[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(ushort[]), Create<ushort[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Decimal[]), Create<Decimal[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(DateTime[]), Create<DateTime[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(Guid[]), Create<Guid[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(String[]), Create<String[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(TimeSpan[]), Create<TimeSpan[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(IPEndPoint[]), Create<IPEndPoint[]>());
|
|
|
|
|
|
|
|
_cachee.Add(typeof(IPAddress[]), Create<IPAddress[]>());
|
|
|
|
|
|
|
|
|
|
|
|
_cachee.Add(typeof(IEnumerable<char>), Create<IEnumerable<char>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<char>), Create<IEnumerable<char>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<Boolean>), Create<IEnumerable<Boolean>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<Boolean>), Create<IEnumerable<Boolean>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<Byte>), Create<IEnumerable<Byte>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<Byte>), Create<IEnumerable<Byte>>());
|
|
|
@ -89,6 +109,25 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
_cachee.Add(typeof(IEnumerable<IPEndPoint>), Create<IEnumerable<IPEndPoint>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<IPEndPoint>), Create<IEnumerable<IPEndPoint>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<IPAddress>), Create<IEnumerable<IPAddress>>());
|
|
|
|
_cachee.Add(typeof(IEnumerable<IPAddress>), Create<IEnumerable<IPAddress>>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(char), typeof(char[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Boolean), typeof(Boolean[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Byte[]), typeof(Byte[][]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Int32), typeof(Int32[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(UInt32), typeof(UInt32[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Int64), typeof(Int64[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(UInt64), typeof(UInt64[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Double), typeof(Double[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(float), typeof(float[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(short), typeof(short[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(ushort), typeof(ushort[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Decimal), typeof(Decimal[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(DateTime), typeof(DateTime[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(Guid), typeof(Guid[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(String), typeof(String[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(TimeSpan), typeof(TimeSpan[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(IPEndPoint), typeof(IPEndPoint[]));
|
|
|
|
|
|
|
|
_arrayTypesCachee.Add(typeof(IPAddress), typeof(IPAddress[]));
|
|
|
|
|
|
|
|
|
|
|
|
_enumTypesCachee.Add(typeof(char), typeof(IEnumerable<char>));
|
|
|
|
_enumTypesCachee.Add(typeof(char), typeof(IEnumerable<char>));
|
|
|
|
_enumTypesCachee.Add(typeof(Boolean), typeof(IEnumerable<Boolean>));
|
|
|
|
_enumTypesCachee.Add(typeof(Boolean), typeof(IEnumerable<Boolean>));
|
|
|
|
_enumTypesCachee.Add(typeof(Byte), typeof(IEnumerable<Byte>));
|
|
|
|
_enumTypesCachee.Add(typeof(Byte), typeof(IEnumerable<Byte>));
|
|
|
@ -210,102 +249,200 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), "WriteTimeSpan").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), "WriteTimeSpan").First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
// Arrays
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
else if (type == typeof(Int32[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadInt32Array").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(char[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadCharArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(UInt32[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUInt32Array").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Boolean[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadBooleanArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Byte[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadByteArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Byte[][]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadByteArrayArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(DateTime[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDateTimeArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Double[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDoubleArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(float[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadFloatArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Guid[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadGuidArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(IPAddress[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadIPArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(IPEndPoint[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadIPEndPointArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Int64[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadInt64Array").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(UInt64[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUInt64Array").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Int16[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadShortArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(UInt16[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUShortArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(String[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadStringArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(Decimal[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDecimalArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == typeof(TimeSpan[]))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadTimeSpanArray").First();
|
|
|
|
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateArrayPredicate<Tw>()).First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Collections
|
|
|
|
// Collections
|
|
|
|
//
|
|
|
|
//
|
|
|
|
else if (type == typeof(IEnumerable<Int32>))
|
|
|
|
else if (type == typeof(IEnumerable<Int32>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadInt32Collection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadInt32Collection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<char>))
|
|
|
|
else if (type == typeof(IEnumerable<char>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadCharCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadCharCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<UInt32>))
|
|
|
|
else if (type == typeof(IEnumerable<UInt32>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUInt32Collection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUInt32Collection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Boolean>))
|
|
|
|
else if (type == typeof(IEnumerable<Boolean>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadBooleanCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadBooleanCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Byte>))
|
|
|
|
else if (type == typeof(IEnumerable<Byte>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadByteCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadByteCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Byte[]>))
|
|
|
|
else if (type == typeof(IEnumerable<Byte[]>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadByteArrayCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadByteArrayCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<DateTime>))
|
|
|
|
else if (type == typeof(IEnumerable<DateTime>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDateTimeCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDateTimeCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Double>))
|
|
|
|
else if (type == typeof(IEnumerable<Double>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDoubleCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDoubleCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<float>))
|
|
|
|
else if (type == typeof(IEnumerable<float>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadFloatCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadFloatCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Guid>))
|
|
|
|
else if (type == typeof(IEnumerable<Guid>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadGuidCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadGuidCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<IPAddress>))
|
|
|
|
else if (type == typeof(IEnumerable<IPAddress>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadIPCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadIPCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<IPEndPoint>))
|
|
|
|
else if (type == typeof(IEnumerable<IPEndPoint>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadIPEndPointCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadIPEndPointCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Int64>))
|
|
|
|
else if (type == typeof(IEnumerable<Int64>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadInt64Collection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadInt64Collection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<UInt64>))
|
|
|
|
else if (type == typeof(IEnumerable<UInt64>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUInt64Collection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUInt64Collection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Int16>))
|
|
|
|
else if (type == typeof(IEnumerable<Int16>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadShortCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadShortCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<UInt16>))
|
|
|
|
else if (type == typeof(IEnumerable<UInt16>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUShortCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadUShortCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<String>))
|
|
|
|
else if (type == typeof(IEnumerable<String>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadStringCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadStringCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<Decimal>))
|
|
|
|
else if (type == typeof(IEnumerable<Decimal>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDecimalCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadDecimalCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == typeof(IEnumerable<TimeSpan>))
|
|
|
|
else if (type == typeof(IEnumerable<TimeSpan>))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadTimeSpanCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.Configure(typeof(MemoryStreamReader), "ReadTimeSpanCollection").First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreatePredicate<Tw>()).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.Configure(typeof(MemoryStreamWriter), CreateCollectionPredicate<Tw>()).First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Not supported
|
|
|
|
// Not supported
|
|
|
@ -317,13 +454,20 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
return wrapper;
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Func<MethodInfo, bool> CreatePredicate<T>()
|
|
|
|
private static Func<MethodInfo, bool> CreateCollectionPredicate<T>()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var typeArg = typeof(T).GetGenericArguments().First();
|
|
|
|
var typeArg = typeof(T).GetGenericArguments().First();
|
|
|
|
return mi => mi.Name.Equals("WriteCollection", StringComparison.Ordinal) &&
|
|
|
|
return mi => mi.Name.Equals("WriteCollection", StringComparison.Ordinal) &&
|
|
|
|
mi.GetParameters().First().ParameterType.GetGenericArguments().First().IsAssignableFrom(typeArg);
|
|
|
|
mi.GetParameters().First().ParameterType.GetGenericArguments().First().IsAssignableFrom(typeArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Func<MethodInfo, bool> CreateArrayPredicate<T>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var typeArg = typeof(T).GetElementType();
|
|
|
|
|
|
|
|
return mi => mi.Name.Equals("WriteArray", StringComparison.Ordinal) &&
|
|
|
|
|
|
|
|
mi.GetParameters().First().ParameterType.GetElementType().IsAssignableFrom(typeArg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly static Dictionary<Type, Wrapper> _concrete_type_cachee = new Dictionary<Type, Wrapper>();
|
|
|
|
private readonly static Dictionary<Type, Wrapper> _concrete_type_cachee = new Dictionary<Type, Wrapper>();
|
|
|
|
private readonly static object _concrete_type_cachee_locker = new object();
|
|
|
|
private readonly static object _concrete_type_cachee_locker = new object();
|
|
|
@ -348,25 +492,31 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
else if (TypeHelpers.IsAssignableToGenericType(type, typeof(IEnumerable<>)))
|
|
|
|
else if (TypeHelpers.IsAssignableToGenericType(type, typeof(IEnumerable<>)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Type elementType;
|
|
|
|
Type elementType;
|
|
|
|
|
|
|
|
var dict = _enumTypesCachee;
|
|
|
|
|
|
|
|
var writeName = "WriteCollection";
|
|
|
|
|
|
|
|
var readName = "ReadCollection";
|
|
|
|
if (TypeHelpers.IsArray(type))
|
|
|
|
if (TypeHelpers.IsArray(type))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
elementType = type.GetElementType();
|
|
|
|
elementType = type.GetElementType();
|
|
|
|
|
|
|
|
dict = _arrayTypesCachee;
|
|
|
|
|
|
|
|
writeName = "WriteArray";
|
|
|
|
|
|
|
|
readName = "ReadArray";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
elementType = type.GetGenericArguments().First();
|
|
|
|
elementType = type.GetGenericArguments().First();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_enumTypesCachee.ContainsKey(elementType))
|
|
|
|
if (dict.ContainsKey(elementType))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_concrete_type_cachee[type] = _cachee[_enumTypesCachee[elementType]];
|
|
|
|
_concrete_type_cachee[type] = _cachee[dict[elementType]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (typeof(IBinarySerializable).IsAssignableFrom(elementType))
|
|
|
|
else if (typeof(IBinarySerializable).IsAssignableFrom(elementType))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var wrapper = new Wrapper { Invoker = InvokeWrapper.Create() };
|
|
|
|
var wrapper = new Wrapper { Invoker = InvokeWrapper.Create() };
|
|
|
|
|
|
|
|
|
|
|
|
wrapper.ReadId = wrapper.Invoker.ConfigureGeneric(typeof(MemoryStreamReader), elementType, "ReadCollection").First();
|
|
|
|
wrapper.ReadId = wrapper.Invoker.ConfigureGeneric(typeof(MemoryStreamReader), elementType, readName).First();
|
|
|
|
wrapper.WriteId = wrapper.Invoker.ConfigureGeneric(typeof(MemoryStreamWriter), elementType,
|
|
|
|
wrapper.WriteId = wrapper.Invoker.ConfigureGeneric(typeof(MemoryStreamWriter), elementType,
|
|
|
|
mi => mi.Name.Equals("WriteCollection") && mi.IsGenericMethod).First();
|
|
|
|
mi => mi.Name.Equals(writeName) && mi.IsGenericMethod).First();
|
|
|
|
_concrete_type_cachee[type] = wrapper;
|
|
|
|
_concrete_type_cachee[type] = wrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|