Example #1
0
        /// <summary>
        /// 快速获取属性值
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public static object GetPropertyValue(object obj, PropertyInfo property)
        {
            if (!property.CanRead)
            {
                return(null);
            }
            FastPropertyGetHandler getter = DynamicCalls.GetPropertyGetter(property);

            return(getter(obj));
        }
Example #2
0
        /// <summary>
        /// 创建一个委托
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static FastCreateInstanceHandler GetFastInstanceCreator(Type type)
        {
            if (type.IsInterface)
            {
                throw new MySoftException("可实例化的对象类型不能是接口!");
            }
            FastCreateInstanceHandler creator = DynamicCalls.GetInstanceCreator(type);

            return(creator);
        }
Example #3
0
 /// <summary>
 /// 快速设置属性值
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="property"></param>
 /// <param name="value"></param>
 public static void SetPropertyValue(object obj, PropertyInfo property, object value)
 {
     if (!property.CanWrite)
     {
         return;
     }
     try
     {
         FastPropertySetHandler setter = DynamicCalls.GetPropertySetter(property);
         value = ConvertValue(property.PropertyType, value);
         setter(obj, value);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
        /// <summary>
        /// 快速调用方法
        /// </summary>
        /// <param name="method"></param>
        /// <returns></returns>
        public static FastInvokeHandler GetFastMethodInvoke(MethodInfo method)
        {
            FastInvokeHandler invoke = DynamicCalls.GetMethodInvoker(method);

            return(invoke);
        }