public object GetValue(object instance) { if (null == this._valueGetter) { if (Monitor.TryEnter(this)) { try { if (null == this._valueGetter) { this._valueGetter = MemberValueGetterContainer.GetMemberValueGetter(this.Definition.Property); } } finally { Monitor.Exit(this); } } else { return(this.Definition.Property.GetMemberValue(instance)); } } return(this._valueGetter(instance)); }
public static MemberValueGetter CreateValueGetter(MemberInfo propertyOrField) { ParameterExpression p = Expression.Parameter(typeof(object), "a"); Expression instance = null; if (!propertyOrField.IsStaticMember()) { instance = Expression.Convert(p, propertyOrField.DeclaringType); } var memberAccess = Expression.MakeMemberAccess(instance, propertyOrField); Type type = ReflectionExtension.GetMemberType(propertyOrField); Expression body = memberAccess; if (type.IsValueType) { body = Expression.Convert(memberAccess, typeof(object)); } var lambda = Expression.Lambda <MemberValueGetter>(body, p); MemberValueGetter ret = lambda.Compile(); return(ret); }
public static MemberValueGetter GetMemberValueGetter(MemberInfo memberInfo) { MemberValueGetter getter = Cache.GetOrAdd(memberInfo, member => { return(DelegateGenerator.CreateValueGetter(member)); }); return(getter); }
public object GetValue(object instance) { if (null == this._valueGetter) { this._valueGetter = MemberValueGetterContainer.GetMemberValueGetter(this.Definition.Property); } return(this._valueGetter(instance)); }
public static MemberValueGetter GetMemberValueGetter(MemberInfo memberInfo) { MemberValueGetter getter = null; if (!Cache.TryGetValue(memberInfo, out getter)) { lock (memberInfo) { if (!Cache.TryGetValue(memberInfo, out getter)) { getter = DelegateGenerator.CreateValueGetter(memberInfo); Cache.GetOrAdd(memberInfo, getter); } } } return(getter); }
public static object FastGetMemberValue(this MemberInfo propertyOrField, object obj) { MemberValueGetter getter = MemberValueGetterContainer.GetMemberValueGetter(propertyOrField); return(getter(obj)); }