Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/aspnet/MessagePack-CSharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@live.com>2022-08-02 17:37:38 +0300
committerGitHub <noreply@github.com>2022-08-02 17:37:38 +0300
commit541ad7c6395b9a74629af7277698e783ceeb3adc (patch)
tree7d3485e0bb47e8970abc0bdcf59093508519edb9
parent1092f85b68ceff6667eadf43081097e02adb77c8 (diff)
parentd75c56acc197c4dac8767192f8f40ace632918ed (diff)
Merge pull request #1461 from LineSmarts/master
Fix for "System.NotImplementedException: byref delegate" (second attempt)
-rw-r--r--src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs45
-rw-r--r--src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs4
2 files changed, 26 insertions, 23 deletions
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs
index 281e20f3..bd6f9b43 100644
--- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs
+++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs
@@ -82,6 +82,22 @@ namespace MessagePack
return GetOrAdd(type).Deserialize_ReadOnlySequence_Options_CancellationToken.Invoke(bytes, options, cancellationToken);
}
+ /// <summary>
+ /// Helper method used by reflection.
+ /// </summary>
+ private static void SerializeSemiGeneric<T>(ref MessagePackWriter writer, object valueObject, MessagePackSerializerOptions options = null)
+ {
+ Serialize(ref writer, (T)valueObject, options);
+ }
+
+ /// <summary>
+ /// Helper method used by reflection.
+ /// </summary>
+ private static object DeserializeSemiGeneric<T>(ref MessagePackReader reader, MessagePackSerializerOptions options = null)
+ {
+ return Deserialize<T>(ref reader, options);
+ }
+
private static async ValueTask<object> DeserializeObjectAsync<T>(Stream stream, MessagePackSerializerOptions options, CancellationToken cancellationToken) => await DeserializeAsync<T>(stream, options, cancellationToken).ConfigureAwait(false);
private static CompiledMethods GetOrAdd(Type type)
@@ -219,39 +235,22 @@ namespace MessagePack
}
{
- // public static void Serialize<T>(ref MessagePackWriter writer, T obj, MessagePackSerializerOptions options)
- MethodInfo serialize = GetMethod(nameof(Serialize), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), null, typeof(MessagePackSerializerOptions) });
+ // private static void SerializeSemiGeneric<T>(ref MessagePackWriter writer, object obj, MessagePackSerializerOptions options)
+ MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(object), typeof(MessagePackSerializerOptions) });
#if ENABLE_IL2CPP
this.Serialize_MessagePackWriter_T_Options = (ref MessagePackWriter x, object y, MessagePackSerializerOptions z) => ThrowRefStructNotSupported();
#else
- ParameterExpression param1 = Expression.Parameter(typeof(MessagePackWriter).MakeByRefType(), "writer");
- ParameterExpression param2 = Expression.Parameter(typeof(object), "obj");
- ParameterExpression param3 = Expression.Parameter(typeof(MessagePackSerializerOptions), "options");
-
- MethodCallExpression body = Expression.Call(
- null,
- serialize,
- param1,
- ti.IsValueType ? Expression.Unbox(param2, type) : Expression.Convert(param2, type),
- param3);
- MessagePackWriterSerialize lambda = Expression.Lambda<MessagePackWriterSerialize>(body, param1, param2, param3).Compile(PreferInterpretation);
-
- this.Serialize_MessagePackWriter_T_Options = lambda;
+ this.Serialize_MessagePackWriter_T_Options = (MessagePackWriterSerialize)serialize.CreateDelegate(typeof(MessagePackWriterSerialize));
#endif
}
{
- // public static T Deserialize<T>(ref MessagePackReader reader, MessagePackSerializerOptions options)
- MethodInfo deserialize = GetMethod(nameof(Deserialize), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) });
+ // private static object DeserializeSemiGeneric<T>(ref MessagePackReader reader, MessagePackSerializerOptions options)
+ MethodInfo deserialize = GetMethod(nameof(DeserializeSemiGeneric), type, new Type[] { typeof(MessagePackReader).MakeByRefType(), typeof(MessagePackSerializerOptions) });
#if ENABLE_IL2CPP
this.Deserialize_MessagePackReader_Options = (ref MessagePackReader reader, MessagePackSerializerOptions options) => { ThrowRefStructNotSupported(); return null; };
#else
- ParameterExpression param1 = Expression.Parameter(typeof(MessagePackReader).MakeByRefType(), "reader");
- ParameterExpression param2 = Expression.Parameter(typeof(MessagePackSerializerOptions), "options");
- UnaryExpression body = Expression.Convert(Expression.Call(null, deserialize, param1, param2), typeof(object));
- MessagePackReaderDeserialize lambda = Expression.Lambda<MessagePackReaderDeserialize>(body, param1, param2).Compile();
-
- this.Deserialize_MessagePackReader_Options = lambda;
+ this.Deserialize_MessagePackReader_Options = (MessagePackReaderDeserialize)deserialize.CreateDelegate(typeof(MessagePackReaderDeserialize));
#endif
}
diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs
index 52b92b0e..643a6643 100644
--- a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs
+++ b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs
@@ -1264,6 +1264,9 @@ namespace MessagePack.Internal
il.Emit(OpCodes.Br, readNext);
}
+#if NET_STANDARD_2_0
+ throw new NotImplementedException("NET_STANDARD_2_0 directive was used");
+#else
if (canOverwrite)
{
automata.EmitMatch(il, buffer, longKey, OnFoundAssignDirect, OnNotFound);
@@ -1272,6 +1275,7 @@ namespace MessagePack.Internal
{
automata.EmitMatch(il, buffer, longKey, OnFoundAssignLocalVariable, OnNotFound);
}
+#endif
il.MarkLabel(readNext);
reader.EmitLdarg();