/// <summary> /// 调用方法(警告,不支持重载) /// </summary> /// <param name="container">原始对象容器</param> /// <param name="methodName"></param> /// <param name="args"></param> /// <returns></returns> public object CallMethod(object container, string methodName, object[] args) { if (container == null) { return(null); } //为了提高处理效率,不考虑重载 Type t = container.GetType(); var cacheKey = string.Concat(t.FullName, ".", methodName); LambdaExpression func; if ((func = CacheHelpers.Get <LambdaExpression>(cacheKey)) == null) { var ms = DynamicHelpers.GetMethods(t, methodName); if (ms.Length == 0) { return(null); } if (ms.Length > 1) { throw new AmbiguousMatchException(string.Concat("Ambiguous match found. name:", methodName)); } var m = ms[0]; var pe = new List <ParameterExpression>(); } //ParameterExpression expA = Expression.Parameter(typeof(string)); //参数a //var expCall = Expression.Call(Expression.Constant(t), m, expA); //Math.Sin(a) //LambdaExpression exp = Expression.Lambda(expCall, "test", new ParameterExpression[] { expA }); //var r = exp.Compile(); return(null); }
private DynamicMethodInfo[] CreateDynamicMethods(Type type, string methodName) { MethodInfo[] mis = DynamicHelpers.GetMethods(type, methodName); DynamicMethodInfo[] list = new DynamicMethodInfo[mis.Length]; Type[] types; for (int i = 0; i < mis.Length; i++) { ParameterInfo[] pis = mis[i].GetParameters(); types = new Type[pis.Length]; for (int j = 0; j < pis.Length; j++) { types[j] = pis[j].ParameterType; } list[i] = CreateExcuteMethodProxy(type, mis[i]); } return(list); }