Example #1
0
        public override 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));
        }
Example #2
0
 public override object GetValue(MemberInfo member, object instance)
 {
     if (member is PropertyInfo)
     {
         return(EmitHelper.CreatePropertyGetterHandler(member as PropertyInfo)(instance));
     }
     if (member is FieldInfo)
     {
         return(EmitHelper.CreateFieldGetterHandler(member as FieldInfo)(instance));
     }
     throw new NotImplementedException();
 }