/// <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)); }
/// <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); }
/// <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; } }
/// <summary> /// 快速调用方法 /// </summary> /// <param name="method"></param> /// <returns></returns> public static FastInvokeHandler GetFastMethodInvoke(MethodInfo method) { FastInvokeHandler invoke = DynamicCalls.GetMethodInvoker(method); return(invoke); }