Permalink
Browse files

removed dynamic hack

  • Loading branch information...
1 parent 0da7e50 commit 63ebee518506aa74eb6d3b9c5b89e636cca7975e @rogeralsing committed Dec 6, 2016
View
@@ -0,0 +1,122 @@
+{
+ "files.exclude": {
+ "*.suo": "explorerExcludedFiles",
+ "*.user": "explorerExcludedFiles",
+ "*.userosscache": "explorerExcludedFiles",
+ "*.sln.docstates": "explorerExcludedFiles",
+ "*.userprefs": "explorerExcludedFiles",
+ "[Dd]ebug/": "explorerExcludedFiles",
+ "[Dd]ebugPublic/": "explorerExcludedFiles",
+ "[Rr]elease/": "explorerExcludedFiles",
+ "[Rr]eleases/": "explorerExcludedFiles",
+ "x64/": "explorerExcludedFiles",
+ "x86/": "explorerExcludedFiles",
+ "build/": "explorerExcludedFiles",
+ "bld/": "explorerExcludedFiles",
+ "[Bb]in/": "explorerExcludedFiles",
+ "[Oo]bj/": "explorerExcludedFiles",
+ ".fake/": "explorerExcludedFiles",
+ "TestResults/": "explorerExcludedFiles",
+ "PerfResults/": "explorerExcludedFiles",
+ ".vs/": "explorerExcludedFiles",
+ "[Tt]est[Rr]esult*/": "explorerExcludedFiles",
+ "[Bb]uild[Ll]og.*": "explorerExcludedFiles",
+ "*.VisualState.xml": "explorerExcludedFiles",
+ "TestResult.xml": "explorerExcludedFiles",
+ "[Dd]ebugPS/": "explorerExcludedFiles",
+ "[Rr]eleasePS/": "explorerExcludedFiles",
+ "dlldata.c": "explorerExcludedFiles",
+ "*_i.c": "explorerExcludedFiles",
+ "*_p.c": "explorerExcludedFiles",
+ "*_i.h": "explorerExcludedFiles",
+ "*.ilk": "explorerExcludedFiles",
+ "*.meta": "explorerExcludedFiles",
+ "*.obj": "explorerExcludedFiles",
+ "*.pch": "explorerExcludedFiles",
+ "*.pdb": "explorerExcludedFiles",
+ "*.pgc": "explorerExcludedFiles",
+ "*.pgd": "explorerExcludedFiles",
+ "*.rsp": "explorerExcludedFiles",
+ "*.sbr": "explorerExcludedFiles",
+ "*.tlb": "explorerExcludedFiles",
+ "*.tli": "explorerExcludedFiles",
+ "*.tlh": "explorerExcludedFiles",
+ "*.tmp": "explorerExcludedFiles",
+ "*.tmp_proj": "explorerExcludedFiles",
+ "*.log": "explorerExcludedFiles",
+ "*.vspscc": "explorerExcludedFiles",
+ "*.vssscc": "explorerExcludedFiles",
+ ".builds": "explorerExcludedFiles",
+ "*.pidb": "explorerExcludedFiles",
+ "*.svclog": "explorerExcludedFiles",
+ "*.scc": "explorerExcludedFiles",
+ "_Chutzpah*": "explorerExcludedFiles",
+ "ipch/": "explorerExcludedFiles",
+ "*.aps": "explorerExcludedFiles",
+ "*.ncb": "explorerExcludedFiles",
+ "*.opensdf": "explorerExcludedFiles",
+ "*.sdf": "explorerExcludedFiles",
+ "*.cachefile": "explorerExcludedFiles",
+ "*.psess": "explorerExcludedFiles",
+ "*.vsp": "explorerExcludedFiles",
+ "*.vspx": "explorerExcludedFiles",
+ "$tf/": "explorerExcludedFiles",
+ "*.gpState": "explorerExcludedFiles",
+ "_ReSharper*/": "explorerExcludedFiles",
+ "*.[Rr]e[Ss]harper": "explorerExcludedFiles",
+ "*.DotSettings.user": "explorerExcludedFiles",
+ ".JustCode": "explorerExcludedFiles",
+ "_TeamCity*": "explorerExcludedFiles",
+ "*.dotCover": "explorerExcludedFiles",
+ "_NCrunch_*": "explorerExcludedFiles",
+ ".*crunch*.local.xml": "explorerExcludedFiles",
+ "*.mm.*": "explorerExcludedFiles",
+ "AutoTest.Net/": "explorerExcludedFiles",
+ ".sass-cache/": "explorerExcludedFiles",
+ "[Ee]xpress/": "explorerExcludedFiles",
+ "DocProject/buildhelp/": "explorerExcludedFiles",
+ "DocProject/Help/*.HxT": "explorerExcludedFiles",
+ "DocProject/Help/*.HxC": "explorerExcludedFiles",
+ "DocProject/Help/*.hhc": "explorerExcludedFiles",
+ "DocProject/Help/*.hhk": "explorerExcludedFiles",
+ "DocProject/Help/*.hhp": "explorerExcludedFiles",
+ "DocProject/Help/Html2": "explorerExcludedFiles",
+ "DocProject/Help/html": "explorerExcludedFiles",
+ "publish/": "explorerExcludedFiles",
+ "*.[Pp]ublish.xml": "explorerExcludedFiles",
+ "*.azurePubxml": "explorerExcludedFiles",
+ "*.pubxml": "explorerExcludedFiles",
+ "*.publishproj": "explorerExcludedFiles",
+ "*.nupkg": "explorerExcludedFiles",
+ "**/packages/*": "explorerExcludedFiles",
+ "!**/packages/build/": "explorerExcludedFiles",
+ "csx/": "explorerExcludedFiles",
+ "*.build.csdef": "explorerExcludedFiles",
+ "AppPackages/": "explorerExcludedFiles",
+ "*.[Cc]ache": "explorerExcludedFiles",
+ "ClientBin/": "explorerExcludedFiles",
+ "[Ss]tyle[Cc]op.*": "explorerExcludedFiles",
+ "~$*": "explorerExcludedFiles",
+ "*~": "explorerExcludedFiles",
+ "*.dbmdl": "explorerExcludedFiles",
+ "*.dbproj.schemaview": "explorerExcludedFiles",
+ "*.pfx": "explorerExcludedFiles",
+ "*.publishsettings": "explorerExcludedFiles",
+ "node_modules/": "explorerExcludedFiles",
+ "bower_components/": "explorerExcludedFiles",
+ "Generated_Code/": "explorerExcludedFiles",
+ "_UpgradeReport_Files/": "explorerExcludedFiles",
+ "Backup*/": "explorerExcludedFiles",
+ "UpgradeLog*.XML": "explorerExcludedFiles",
+ "UpgradeLog*.htm": "explorerExcludedFiles",
+ "*.mdf": "explorerExcludedFiles",
+ "*.ldf": "explorerExcludedFiles",
+ "*.rdl.data": "explorerExcludedFiles",
+ "*.bim.layout": "explorerExcludedFiles",
+ "*.bim_*.settings": "explorerExcludedFiles",
+ "FakesAssemblies/": "explorerExcludedFiles",
+ ".ntvs_analysis.dat": "explorerExcludedFiles",
+ "*.plg": "explorerExcludedFiles",
+ "*.opt": "explorerExcludedFiles"
+ }
+}
@@ -7,6 +7,7 @@
using System;
using System.Collections.Concurrent;
using System.IO;
+using System.Reflection;
using Wire.Extensions;
using Wire.ValueSerializers;
@@ -19,23 +20,34 @@ public class ArraySerializerFactory : ValueSerializerFactory
public override bool CanDeserialize(Serializer serializer, Type type) => CanSerialize(serializer, type);
private static void WriteValues<T>(T[] array, Stream stream, Type elementType, ValueSerializer elementSerializer,
- SerializerSession session)
+ SerializerSession session, bool preserveObjectReferences)
{
+ if (preserveObjectReferences)
+ {
+ session.TrackSerializedObject(array);
+ }
+
Int32Serializer.WriteValueImpl(stream, array.Length, session);
- var preserveObjectReferences = session.Serializer.Options.PreserveObjectReferences;
foreach (var value in array)
{
stream.WriteObject(value, elementType, elementSerializer, preserveObjectReferences, session);
}
}
- private static void ReadValues<T>(int length, Stream stream, DeserializerSession session, T[] array)
+ private static object ReadValues<T>(Stream stream, DeserializerSession session, bool preserveObjectReferences)
{
+ var length = stream.ReadInt32(session);
+ var array = new T[length];
+ if (preserveObjectReferences)
+ {
+ session.TrackDeserializedObject(array);
+ }
for (var i = 0; i < length; i++)
{
var value = (T) stream.ReadObject(session);
array[i] = value;
}
+ return array;
}
public override ValueSerializer BuildSerializer(Serializer serializer, Type type,
@@ -46,28 +58,21 @@ private static void ReadValues<T>(int length, Stream stream, DeserializerSession
var elementType = type.GetElementType();
var elementSerializer = serializer.GetSerializerByType(elementType);
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
- //TODO: code gen this part
- ObjectReader reader = (stream, session) =>
- {
- var length = stream.ReadInt32(session);
- var array = Array.CreateInstance(elementType, length); //create the array
- if (preserveObjectReferences)
- {
- session.TrackDeserializedObject(array);
- }
- ReadValues(length, stream, session, (dynamic) array);
+ var readGeneric = GetType().GetTypeInfo().GetMethod(nameof(ReadValues), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(elementType);
+ var writeGeneric = GetType().GetTypeInfo().GetMethod(nameof(WriteValues), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(elementType);
+
- return array;
+ ObjectReader reader = (stream, session) =>
+ {
+ //Stream stream, DeserializerSession session, bool preserveObjectReferences
+ var res = readGeneric.Invoke(null, new object[] {stream, session, preserveObjectReferences});
+ return res;
};
ObjectWriter writer = (stream, arr, session) =>
{
- if (preserveObjectReferences)
- {
- session.TrackSerializedObject(arr);
- }
-
- WriteValues((dynamic) arr, stream, elementType, elementSerializer, session);
+ //T[] array, Stream stream, Type elementType, ValueSerializer elementSerializer, SerializerSession session, bool preserveObjectReferences
+ writeGeneric.Invoke(null, new[] {arr, stream, elementType, elementSerializer, session, preserveObjectReferences});
};
arraySerializer.Initialize(reader, writer);
typeMapping.TryAdd(type, arraySerializer);
@@ -33,41 +33,34 @@ private static bool IsInterface(Type type)
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
var ser = new ObjectSerializer(type);
typeMapping.TryAdd(type, ser);
- var elementType = type.GetGenericArguments()[0];
+ var elementType = type.GetTypeInfo().GetGenericArguments()[0];
var elementSerializer = serializer.GetSerializerByType(elementType);
- var readGeneric = GetType().GetMethod(nameof(ReadHashSet), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(elementType);
- var writeGeneric = GetType().GetMethod(nameof(WriteHashSet), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(elementType);
+ var readGeneric = GetType().GetTypeInfo().GetMethod(nameof(ReadHashSet), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(elementType);
+ var writeGeneric = GetType().GetTypeInfo().GetMethod(nameof(WriteHashSet), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(elementType);
ObjectReader reader = (stream, session) =>
{
-#pragma warning disable CS0162 // Unreachable code detected
- var instance = Activator.CreateInstance(type);
-#pragma warning restore CS0162 // Unreachable code detected
- if (preserveObjectReferences)
- {
- session.TrackDeserializedObject(instance);
- }
- var res = readGeneric.Invoke(null, new object[] {stream, session, elementSerializer});
+ var res = readGeneric.Invoke(null, new object[] {stream, session, preserveObjectReferences});
return res;
};
ObjectWriter writer = (stream, obj, session) =>
{
- if (preserveObjectReferences)
- {
- session.TrackSerializedObject(obj);
- }
+
writeGeneric.Invoke(null, new[] {obj, stream, session,elementType, elementSerializer, preserveObjectReferences});
};
ser.Initialize(reader, writer);
return ser;
}
- private static HashSet<T> ReadHashSet<T>(Stream stream, DeserializerSession session,
- ValueSerializer elementSerializer)
+ private static HashSet<T> ReadHashSet<T>(Stream stream, DeserializerSession session,bool preserveObjectReferences)
{
var set = new HashSet<T>();
+ if (preserveObjectReferences)
+ {
+ session.TrackDeserializedObject(set);
+ }
var count = stream.ReadInt32(session);
for (var i = 0; i < count; i++)
{
@@ -78,13 +71,17 @@ private static bool IsInterface(Type type)
}
private static void WriteHashSet<T>(HashSet<T> set, Stream stream, SerializerSession session, Type elementType,
- ValueSerializer elementSerializer, bool preserveReferences)
+ ValueSerializer elementSerializer, bool preserveObjectReferences)
{
+ if (preserveObjectReferences)
+ {
+ session.TrackSerializedObject(set);
+ }
// ReSharper disable once PossibleNullReferenceException
Int32Serializer.WriteValueImpl(stream, set.Count, session);
foreach (var item in set)
{
- stream.WriteObject(item,elementType,elementSerializer,preserveReferences,session);
+ stream.WriteObject(item,elementType,elementSerializer, preserveObjectReferences, session);
}
}
}
@@ -1,17 +1,15 @@
{
- "version": "0.8.1-*",
+ "version": "0.8.2-*",
"description": "Wire, fast binary POCO serializer",
"authors": [
"Roger Johansson"
],
"packOptions": {
"tags": [
"serialization",
- "akka.net",
"poco"
],
- "projectUrl": "https://github.com/akkadotnet/Wire",
- "licenseUrl": "https://github.com/akkadotnet/Wire/blob/master/LICENSE",
+ "projectUrl": "https://github.com/rogeralsing/Wire",
"iconUrl": "https://raw.githubusercontent.com/hmemcpy/NServiceBus.Wire/master/icon.png"
},
"dependencies": {
View
@@ -1,17 +1,16 @@
{
- "version": "0.8.1-*",
+ "version": "0.8.2-*",
"description": "Wire, fast binary POCO serializer",
"authors": [
"Roger Johansson"
],
"packOptions": {
"tags": [
"serialization",
- "akka.net",
"poco"
],
- "projectUrl": "https://github.com/akkadotnet/Wire",
- "licenseUrl": "https://github.com/akkadotnet/Wire/blob/master/LICENSE",
+ "projectUrl": "https://github.com/rogeralsing/Wire",
+ "licenseUrl": "",
"iconUrl": "https://raw.githubusercontent.com/hmemcpy/NServiceBus.Wire/master/icon.png"
},
"dependencies": {

0 comments on commit 63ebee5

Please sign in to comment.