예제 #1
0
    public static object GetValue(MemberInfo memberInfo, object instance)
    {
        Func <object, object> getter;

        if (memberInfo is PropertyInfo)
        {
            var propertyInfo = memberInfo as PropertyInfo;
            var key          = propertyInfo.GetGetMethod().MethodHandle.Value;
            if (!getterCache.TryGetValue(key, out getter))
            {
                getterCache.Add(key, getter = EmitHelper.CreatePropertyGetterHandler(propertyInfo));
            }
        }
        else if (memberInfo is FieldInfo)
        {
            var fieldInfo = memberInfo as FieldInfo;
            if (!getterCache.TryGetValue(fieldInfo.FieldHandle.Value, out getter))
            {
                getterCache.Add(fieldInfo.FieldHandle.Value, getter = EmitHelper.CreateFieldGetterHandler(fieldInfo));
            }
        }
        else
        {
            throw new NotImplementedException();
        }

        return(getter(instance));
    }