示例#1
0
        /// <summary>
        /// 获取属性的信息(不使用缓存)
        /// </summary>
        /// <param name="proName">属性名</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static PropertyInfoHandle GetPropertyInfoHandleWithOutCache(string proName, Type type)
        {
            FastPropertyHandler getHandle = GetGetMethodInfo(proName, type);
            FastPropertyHandler setHandle = GetSetMethodInfo(proName, type);
            PropertyInfo        pinf      = type.GetProperty(proName, AllBindingFlags);//获取子元素集合的属性
            Type proType = null;

            if (pinf != null)
            {
                proType = pinf.PropertyType;
            }
            PropertyInfoHandle propertyHandle = new PropertyInfoHandle(type, getHandle, setHandle, proType, proName);

            return(propertyHandle);
        }
示例#2
0
        /// <summary>
        /// 获取属性的信息
        /// </summary>
        /// <param name="proName">属性名</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static PropertyInfoHandle GetPropertyInfoHandle(string proName, Type type)
        {
            string             fullName       = type.FullName + "." + proName;
            PropertyInfoHandle propertyHandle = null;

            if (!dicProperty.TryGetValue(fullName, out propertyHandle))
            {
                using (Lock objLock = new Lock(dicProperty))
                {
                    propertyHandle        = GetPropertyInfoHandleWithOutCache(proName, type);
                    dicProperty[fullName] = propertyHandle;
                }
            }

            return(propertyHandle);
        }
示例#3
0
        /// <summary>
        /// 获取对象赋值
        /// </summary>
        /// <param name="args">对象</param>
        /// <param name="value">值</param>
        /// <param name="propertyName">属性名</param>
        /// <param name="objType">对象类型</param>
        public static object GetValue(object args, string propertyName, Type objType)
        {
            PropertyInfoHandle fastInvoker = GetPropertyInfoHandle(propertyName, objType);

            return(fastInvoker.GetValue(args));
        }
示例#4
0
        /// <summary>
        /// 对对象赋值
        /// </summary>
        /// <param name="args">对象</param>
        /// <param name="value">值</param>
        /// <param name="propertyName">属性名</param>
        /// <param name="objType">对象类型</param>
        public static void SetValue(object args, object value, string propertyName, Type objType)
        {
            PropertyInfoHandle fastInvoker = GetPropertyInfoHandle(propertyName, objType);

            fastInvoker.SetValue(args, value);
        }