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

Commit 50ee2e9

Browse files
committed
Merge branch 'master' of https://github.com/ServiceStack/ServiceStack.Text into netcore
2 parents 7cbc1ea + 5e03137 commit 50ee2e9

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/ServiceStack.Text/Reflection/StaticAccessors.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
using System;
1313
using System.Collections.Generic;
14+
using System.Linq;
1415
using System.Reflection;
1516
using System.Threading;
1617
using ServiceStack.Text;
@@ -26,12 +27,16 @@ public static class StaticAccessors
2627

2728
public static Func<object, object> GetFastGetter(this Type type, string propName)
2829
{
29-
var key = $"{type.Namespace}.{type.Name}::{propName}";
30+
var key = $"{type.FullName}::{propName}";
3031
Func<object, object> fn;
3132
if (getterFnCache.TryGetValue(key, out fn))
3233
return fn;
3334

34-
fn = GetValueGetter(type.GetPropertyInfo(propName));
35+
var pi = type.GetPropertyInfo(propName);
36+
if (pi == null)
37+
return null;
38+
39+
fn = GetValueGetter(pi);
3540

3641
Dictionary<string, Func<object, object>> snapshot, newCache;
3742
do
@@ -49,12 +54,16 @@ public static Func<object, object> GetFastGetter(this Type type, string propName
4954

5055
public static Action<object, object> GetFastSetter(this Type type, string propName)
5156
{
52-
var key = $"{type.Namespace}.{type.Name}::{propName}";
57+
var key = $"{type.FullName}::{propName}";
5358
Action<object, object> fn;
5459
if (setterFnCache.TryGetValue(key, out fn))
5560
return fn;
5661

57-
fn = GetValueSetter(type.GetPropertyInfo(propName));
62+
var pi = type.GetPropertyInfo(propName);
63+
if (pi == null)
64+
return null;
65+
66+
fn = GetValueSetter(pi);
5867

5968
Dictionary<string, Action<object, object>> snapshot, newCache;
6069
do
@@ -86,7 +95,7 @@ public static Func<object, object> GetValueGetter(this PropertyInfo propertyInfo
8695
#else
8796

8897
var instance = Expression.Parameter(typeof(object), "i");
89-
var convertInstance = Expression.TypeAs(instance, propertyInfo.DeclaringType);
98+
var convertInstance = Expression.TypeAs(instance, type);
9099
var property = Expression.Property(convertInstance, propertyInfo);
91100
var convertProperty = Expression.TypeAs(property, typeof(object));
92101
return Expression.Lambda<Func<object, object>>(convertProperty, instance).Compile();
@@ -129,17 +138,17 @@ public static Func<T, object> GetValueGetter<T>(this FieldInfo fieldInfo)
129138
}
130139

131140
#if !XBOX
132-
public static Action<object, object> GetValueSetter(this PropertyInfo propertyInfo, Type instanceType)
141+
public static Action<object, object> GetValueSetter(this PropertyInfo propertyInfo)
133142
{
134-
return GetValueSetter(propertyInfo);
143+
return GetValueSetter(propertyInfo, propertyInfo.DeclaringType);
135144
}
136145

137-
public static Action<object, object> GetValueSetter(this PropertyInfo propertyInfo)
146+
public static Action<object, object> GetValueSetter(this PropertyInfo propertyInfo, Type instanceType)
138147
{
139148
var instance = Expression.Parameter(typeof(object), "i");
140149
var argument = Expression.Parameter(typeof(object), "a");
141150

142-
var type = (Expression)Expression.TypeAs(instance, propertyInfo.DeclaringType);
151+
var type = (Expression)Expression.TypeAs(instance, instanceType);
143152

144153
var setterCall = Expression.Call(
145154
type,

0 commit comments

Comments
 (0)