Skip to content

Commit 75976df

Browse files
committed
Fix nullable serializer generation may fail in netstandard 1.3.
1 parent a179af5 commit 75976df

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/MsgPack/Serialization/AbstractSerializers/SerializerBuilder`2.Nullable.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region -- License Terms --
1+
#region -- License Terms --
22
//
33
// MessagePack for CLI
44
//
@@ -20,6 +20,9 @@
2020

2121
using System;
2222
using System.Linq;
23+
#if FEATURE_TAP
24+
using System.Threading.Tasks;
25+
#endif // FEATURE_TAP
2326

2427
namespace MsgPack.Serialization.AbstractSerializers
2528
{
@@ -77,7 +80,11 @@ private void BuildNullableUnpackFrom( TContext context, Type underlyingType, boo
7780
#if FEATURE_TAP
7881
isAsync ? MethodName.UnpackFromAsyncCore :
7982
#endif // FEATURE_TAP
80-
MethodName.UnpackFromCore;
83+
MethodName.UnpackFromCore;
84+
#if FEATURE_TAP
85+
var asyncMethodReturnType = typeof( Task<> ).MakeGenericType( underlyingType );
86+
#endif // FEATURE_TAP
87+
8188
context.BeginMethodOverride( methodName );
8289

8390
var result = this.DeclareLocal( context, this.TargetType, "result" );
@@ -87,12 +94,15 @@ private void BuildNullableUnpackFrom( TContext context, Type underlyingType, boo
8794
context,
8895
this.EmitGetSerializerExpression( context, underlyingType, null, null ),
8996
#if FEATURE_TAP
90-
isAsync ? typeof( MessagePackSerializer<> ).MakeGenericType( underlyingType ).GetMethod( "UnpackFromAsync", SerializerBuilderHelper.UnpackFromAsyncParameterTypes ) :
97+
isAsync
98+
? typeof( MessagePackSerializer<> ).MakeGenericType( underlyingType ).GetMethods()
99+
.Single( m => m.IsPublic && m.Name == "UnpackFromAsync" && m.ReturnType == asyncMethodReturnType && m.GetParameterTypes().SequenceEqual( SerializerBuilderHelper.UnpackFromAsyncParameterTypes ) ) :
91100
#endif // FEATURE_TAP
92101
typeof( MessagePackSerializer<> ).MakeGenericType( underlyingType ).GetMethod( "UnpackFrom" ),
93102
context.Unpacker
94103
);
95104

105+
96106
context.EndMethodOverride(
97107
methodName,
98108
this.EmitRetrunStatement(

0 commit comments

Comments
 (0)