//获取类反射对象
Type types = Assembly.Load("App_Code").CreateInstance("AnalyFunctions").GetType();
object[] objec2 = { (object)valuess };
string fac="method1";
//获取方法的返回值
values2 = (string)types.GetMethod(fac).Invoke(null, objec2);
若method1方法存在重载,则报参数不匹配错误,如果能解决这个问题!

解决方案 »

  1.   

    GetMethod的有一个重载是可以指定方法参数的
                 //查找一个参数是int和string的method1方法
                  Type[] paramTypes = {typeof(int),typeof(string)};
                string fac="method1";
                GetType().GetMethod(fac, paramTypes).Invoke(...);
      

  2.   

                //获取方法的返回值
                values2 = (string)types.GetMethod(fac).Invoke(null, objec2);
                //改为            //获取方法的返回值
                values2 = (string)types.GetMethod(fac).Invoke(objec2, null);
      

  3.   


     private MethodInfo GetMethodInfo(Type type, string methodName, int paramCount)
            {
                return type.GetMethods().FirstOrDefault(m => { return m.Name == methodName && m.GetParameters().Count() == paramCount; });
            }        MethodInfo method = GetMethodInfo(this.GetType(), "ABC", 0);
            if (method != null)
            {
                //todo
            }