/// <summary>通过传入参数字典快速调用静态方法</summary> /// <typeparam name="TTarget"></typeparam> /// <typeparam name="TResult"></typeparam> /// <param name="name"></param> /// <param name="parameters"></param> /// <returns></returns> public static TResult InvokeByDictionaryParameter <TTarget, TResult>(String name, IDictionary parameters) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } MethodInfoX mix = Create(typeof(TTarget), name); if (mix == null) { throw new Exception(string.Format("类{0}中无法找到{1}方法!", typeof(TTarget).Name, name)); } return((TResult)mix.InvokeByDictionaryParameter(null, parameters)); }
/// <summary>快速调用静态方法</summary> /// <typeparam name="TTarget">目标类型</typeparam> /// <typeparam name="TResult">返回类型</typeparam> /// <param name="name"></param> /// <param name="parameters"></param> /// <returns></returns> public static TResult Invoke <TTarget, TResult>(String name, params Object[] parameters) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } MethodInfoX mix = Create(typeof(TTarget), name, TypeX.GetTypeArray(parameters)); if (mix == null) { throw new Exception(string.Format("类{0}中无法找到{1}方法!", typeof(TTarget).Name, name)); } return((TResult)mix.Invoke(null, parameters)); }
/// <summary>通过传入参数字典快速调用方法</summary> /// <typeparam name="TResult"></typeparam> /// <param name="target"></param> /// <param name="name"></param> /// <param name="parameters"></param> /// <returns></returns> public static TResult InvokeByDictionaryParameter <TResult>(Object target, String name, IDictionary parameters) { if (target == null) { throw new ArgumentNullException("target"); } if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } MethodInfoX mix = Create(target.GetType(), name); if (mix == null) { throw new Exception(string.Format("类{0}中无法找到{1}方法!", target.GetType().Name, name)); } return((TResult)mix.InvokeByDictionaryParameter(target, parameters)); }
/// <summary>创建快速访问成员</summary> /// <param name="member"></param> /// <returns></returns> public static MemberInfoX Create(MemberInfo member) { if (member == null) { return(null); } switch (member.MemberType) { case MemberTypes.All: break; case MemberTypes.Constructor: return(ConstructorInfoX.Create(member as ConstructorInfo)); case MemberTypes.Custom: break; case MemberTypes.Event: return(EventInfoX.Create(member as EventInfo)); case MemberTypes.Field: return(FieldInfoX.Create(member as FieldInfo)); case MemberTypes.Method: return(MethodInfoX.Create(member as MethodInfo)); case MemberTypes.Property: return(PropertyInfoX.Create(member as PropertyInfo)); case MemberTypes.TypeInfo: case MemberTypes.NestedType: return(TypeX.Create(member as Type)); default: break; } return(null); }