/// <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> /// <returns></returns> public static object GetPropertyValue(object obj, PropertyInfo property) { if (obj == null) { return(null); } if (!property.CanRead) { return(null); } try { FastPropertyGetHandler getter = DynamicCalls.GetPropertyGetter(property); return(getter(obj)); } catch (Exception ex) { throw ex; } }
/// <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 (obj == null) { return; } 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); }