diff --git a/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs b/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs index 281e20f31..bd6f9b431 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 @@ public static object Deserialize(Type type, ReadOnlySequence<byte> bytes, Messag 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 @@ internal CompiledMethods(Type type) } { - // 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 52b92b0e4..643a6643b 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 @@ void OnNotFound() 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 @@ void OnNotFound() { automata.EmitMatch(il, buffer, longKey, OnFoundAssignLocalVariable, OnNotFound); } +#endif il.MarkLabel(readNext); reader.EmitLdarg();