/// <summary>
        /// 通过属性信息获得成员连接器
        /// </summary>
        /// <param name="property">属性</param>
        /// <returns>属性对象</returns>
        /// <example>
        /// <code lang="c#">
        /// <![CDATA[
        ///     public class UserInfo{
        ///         public int ID{get;set;}
        ///
        ///         public string Name{get;set;}
        ///     }
        ///     UserInfo user= new UserInfo();
        ///     user.ID=1;
        ///
        ///     PropertyInfo property=typeof(UserInfo).GetProperty("ID");
        ///
        ///     var member=Reflector.GetProperty(property);
        ///
        ///     int value=member.GetValue(user).ToType<int>();
        ///
        ///     member.SetValue(user,2);
        ///
        /// ]]>
        /// </code>
        /// </example>
        public static IMemberAccessor GetProperty(PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            IMemberAccessor accessor;

            if (_propertyCache.TryGetValue(property, out accessor))
            {
                return(accessor);
            }

            lock (_propertyCache)
            {
                if (!_propertyCache.TryGetValue(property, out accessor))
                {
                    accessor = _refFactory.GetPropertyAccessor(property);
                    _propertyCache[property] = accessor;
                }
            }

            return(accessor);
        }
Esempio n. 2
0
        /// <summary>
        /// 通过属性信息获得成员连接器
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public static IMemberAccessor GetAccessor(PropertyInfo property)
        {
            IMemberAccessor accessor;

            if (_propertyCache.TryGetValue(property, out accessor))
            {
                return(accessor);
            }

            lock (_propertyCache)
            {
                if (!_propertyCache.TryGetValue(property, out accessor))
                {
                    accessor = _refFactory.GetPropertyAccessor(property);
                    _propertyCache[property] = accessor;
                }
            }

            return(accessor);
        }