Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 033180d

Browse files
committed
Add fix for Mono returning null in TypeAccessor
1 parent c15cdd4 commit 033180d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ServiceStack.Text/PclExport.Net40.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,8 @@ private static void WriteGetter(ILGenerator il, Type type, PropertyInfo[] props,
14451445
foreach (PropertyInfo prop in props)
14461446
{
14471447
if (prop.GetIndexParameters().Length != 0 || !prop.CanRead) continue;
1448+
var getFn = prop.GetGetMethod();
1449+
if (getFn == null) continue; //Mono
14481450

14491451
Label next = il.DefineLabel();
14501452
il.Emit(propName);
@@ -1454,7 +1456,7 @@ private static void WriteGetter(ILGenerator il, Type type, PropertyInfo[] props,
14541456
// match:
14551457
il.Emit(target);
14561458
Cast(il, type, loc);
1457-
il.EmitCall(type.IsValueType ? OpCodes.Call : OpCodes.Callvirt, prop.GetGetMethod(), null);
1459+
il.EmitCall(type.IsValueType ? OpCodes.Call : OpCodes.Callvirt, getFn, null);
14581460
if (prop.PropertyType.IsValueType)
14591461
{
14601462
il.Emit(OpCodes.Box, prop.PropertyType);
@@ -1503,6 +1505,8 @@ private static void WriteSetter(ILGenerator il, Type type, PropertyInfo[] props,
15031505
foreach (PropertyInfo prop in props)
15041506
{
15051507
if (prop.GetIndexParameters().Length != 0 || !prop.CanWrite) continue;
1508+
var setFn = prop.GetSetMethod();
1509+
if (setFn == null) continue; //Mono
15061510

15071511
Label next = il.DefineLabel();
15081512
il.Emit(propName);
@@ -1514,7 +1518,7 @@ private static void WriteSetter(ILGenerator il, Type type, PropertyInfo[] props,
15141518
Cast(il, type, loc);
15151519
il.Emit(value);
15161520
Cast(il, prop.PropertyType, null);
1517-
il.EmitCall(type.IsValueType ? OpCodes.Call : OpCodes.Callvirt, prop.GetSetMethod(), null);
1521+
il.EmitCall(type.IsValueType ? OpCodes.Call : OpCodes.Callvirt, setFn, null);
15181522
il.Emit(OpCodes.Ret);
15191523
// not match:
15201524
il.MarkLabel(next);

0 commit comments

Comments
 (0)