Skip to content

Commit a36d4b2

Browse files
committed
Fix NRE in netstandard 1.x.
1 parent 88636b5 commit a36d4b2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/MsgPack/ReflectionAbstractions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static MethodInfo GetRuntimeMethod( this Type source, string name, Type[]
212212
);
213213
}
214214

215-
#else
215+
#else // NETSTANDARD1_1 || NETSTANDARD1_3
216216
public static MethodInfo GetRuntimeMethod( this Type source, string name, Type[] parameters )
217217
{
218218
return
@@ -242,6 +242,13 @@ public static PropertyInfo GetRuntimeProperty( this Type source, string name )
242242
);
243243
}
244244

245+
#if NET35 || SILVERLIGHT
246+
public static IEnumerable<PropertyInfo> GetRuntimeProperties( this Type source )
247+
{
248+
return source.GetProperties( BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic );
249+
}
250+
#endif // NET35 || SILVERLIGHT
251+
245252
#if DEBUG
246253
public static FieldInfo GetRuntimeField( this Type source, string name )
247254
{

src/MsgPack/Serialization/Metadata/_MessagePackSerializer.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#endregion -- License Terms --
2020

2121
using System;
22+
using System.Linq;
2223
using System.Reflection;
2324

2425
namespace MsgPack.Serialization.Metadata
@@ -27,8 +28,12 @@ namespace MsgPack.Serialization.Metadata
2728
internal static class _MessagePackSerializer
2829
{
2930
// ReSharper disable InconsistentNaming
30-
public static readonly MethodInfo Create1_Method = typeof( MessagePackSerializer ).GetRuntimeMethod( nameof( MessagePackSerializer.Create ), new[] { typeof( SerializationContext ) } );
31+
public static readonly MethodInfo Create1_Method = typeof( MessagePackSerializer ).GetMethod( nameof( MessagePackSerializer.Create ), new[] { typeof( SerializationContext ) } );
3132
// ReSharper restore InconsistentNaming
32-
public static readonly PropertyInfo OwnerContext = typeof( MessagePackSerializer ).GetRuntimeProperty( nameof( MessagePackSerializer.OwnerContext ) );
33+
public static readonly PropertyInfo OwnerContext =
34+
typeof( MessagePackSerializer )
35+
// Use LINQ to get non public property in netstandard 1.x
36+
.GetRuntimeProperties()
37+
.Single( p => p.Name == nameof( MessagePackSerializer.OwnerContext ) );
3338
}
3439
}

0 commit comments

Comments
 (0)