Skip to content

Commit a179af5

Browse files
committed
Fix reflection abstraction inconsistency for corefx.
1 parent bbe7cd4 commit a179af5

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/MsgPack/ReflectionAbstractions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static MethodInfo GetRuntimeMethod( this Type source, string name, Type[]
208208
return
209209
source.GetRuntimeMethods()
210210
.SingleOrDefault(
211-
m => m.Name == name && m.GetParameters().Select( p => p.ParameterType ).SequenceEqual( parameters )
211+
m => m.IsPublic && m.Name == name && m.GetParameters().Select( p => p.ParameterType ).SequenceEqual( parameters )
212212
);
213213
}
214214

@@ -218,7 +218,7 @@ public static MethodInfo GetRuntimeMethod( this Type source, string name, Type[]
218218
return
219219
source.GetMethod(
220220
name,
221-
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
221+
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
222222
null,
223223
parameters,
224224
null
@@ -280,7 +280,7 @@ public static Delegate CreateDelegate( this MethodInfo source, Type delegateType
280280
#if NETSTANDARD1_1 || NETSTANDARD1_3
281281
public static MethodInfo GetMethod( this Type source, string name )
282282
{
283-
return source.GetRuntimeMethods().SingleOrDefault( m => m.Name == name && m.DeclaringType == source );
283+
return source.GetRuntimeMethods().SingleOrDefault( m => m.IsPublic && m.Name == name && m.DeclaringType == source );
284284
}
285285

286286
public static MethodInfo GetMethod( this Type source, string name, Type[] parameters )

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

Lines changed: 3 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
//
@@ -526,7 +526,7 @@ protected internal TConstruct EmitUnpackToInitialization( TContext context )
526526
context.GetDeclaredField( FieldName.UnpackTo ),
527527
this.EmitNewPrivateMethodDelegateExpression(
528528
context,
529-
this.BaseClass.GetRuntimeMethod( MethodName.UnpackToCore, parameterTypes )
529+
this.BaseClass.GetRuntimeMethods().Single( m => m.Name == MethodName.UnpackToCore && m.GetParameterTypes().SequenceEqual( parameterTypes ) )
530530
)
531531
);
532532

@@ -542,7 +542,7 @@ protected internal TConstruct EmitUnpackToInitialization( TContext context )
542542
context.GetDeclaredField( FieldName.UnpackTo + "Async" ),
543543
this.EmitNewPrivateMethodDelegateExpression(
544544
context,
545-
this.BaseClass.GetRuntimeMethod( MethodName.UnpackToAsyncCore, asyncParameterTypes )
545+
this.BaseClass.GetRuntimeMethods().Single( m => m.Name == MethodName.UnpackToAsyncCore && m.GetParameterTypes().SequenceEqual( asyncParameterTypes ) )
546546
)
547547
);
548548

src/MsgPack/Serialization/MessagePackSerializer.Factories.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
using System;
3434
using System.IO;
3535
using System.Globalization;
36+
#if AOT
37+
using System.Linq;
38+
using System.Reflection;
39+
#endif // AOT
3640
using System.Runtime.Serialization;
3741

3842
using MsgPack.Serialization.DefaultSerializers;
@@ -537,9 +541,10 @@ public static MessagePackSerializer Get( Type targetType, SerializationContext c
537541

538542
#if AOT
539543
private static readonly System.Reflection.MethodInfo CreateInternal_2 =
540-
typeof( MessagePackSerializer ).GetRuntimeMethod(
541-
"CreateInternal",
542-
new []{ typeof( SerializationContext ), typeof( PolymorphismSchema ) }
544+
typeof( MessagePackSerializer ).GetRuntimeMethods()
545+
.Single( m =>
546+
m.Name == "CreateInternal"
547+
&& m.GetParameterTypes().SequenceEqual( new []{ typeof( SerializationContext ), typeof( PolymorphismSchema ) } )
543548
);
544549

545550
internal static MessagePackSerializer CreateInternal( SerializationContext context, Type targetType, PolymorphismSchema schema )

0 commit comments

Comments
 (0)