Assembly amb = Assembly.LoadFrom(@"F:\Job\组件商城20111118\商城代码2011-11-18\Source Code\MSBLL\bin\Debug\MSBLL.dll");
                Type tt = amb.GetType("MSBLL.IndentManage");
                object obj = amb.CreateInstance("MSBLL.IndentManage");
                MethodInfo[] methodInfo = tt.GetMethods();
                MethodInfo info = tt.GetMethod("DownUrl");MSBLL程序集中的类IndentManage的方法DownUrl如下:
       public string DownUrl(string id)
       {
           string sqlstr = "select file_path from MS_Files where moduleid=" + id;
           return DbHelperSQL.ExSqlReturn(sqlstr);
       }我怎么用反射机制的Invoke来调用这个方法??
请高手指点,不胜感激!!

解决方案 »

  1.   

    info.Invoke(obj,new object[]{"1"})
      

  2.   

    再次感谢楼上的,同时想问下,怎么调用DbHelperSQL.ExSqlReturn(sqlstr);???其位于MSDAL命名空间下的DbHelperSQL类的方法:
            public static string ExSqlReturn(string Sqlstring)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand(Sqlstring, connection))
                    {
                        try
                        {
                            connection.Open();
                            if (cmd.ExecuteScalar() == null)
                                return "";
                            else
                                return cmd.ExecuteScalar().ToString();
                        }
                        catch (System.Data.SqlClient.SqlException e)
                        {
                            connection.Close();
                            throw e;
                        }
                    }
                }
            }
      

  3.   

    这是静态方法,你先找到那个类,方法;类似:
    Type tt = amb.GetType("MSDAL.DbHelperSQL");
    MethodInfo info = tt.GetMethod("ExSqlReturn");
    info.Invoke(null,new object[]{"1"})
      

  4.   

    Assembly amb = Assembly.LoadFrom(@"F:\Job\组件商城20111118\商城代码2011-11-18\Source Code\MSBLL\bin\Debug\MSBLL.dll");
      Type tt = amb.GetType("MSBLL.IndentManage");
      object obj = amb.CreateInstance("MSBLL.IndentManage");
      MethodInfo[] methodInfo = tt.GetMethods();
      MethodInfo info = tt.GetMethod("DownUrl");MSBLL程序集中的类IndentManage的方法DownUrl如下:
      public string DownUrl(string id)
      {
      string sqlstr = "select file_path from MS_Files where moduleid=" + id;
      return DbHelperSQL.ExSqlReturn(sqlstr);
      }我怎么用反射机制的Invoke来调用这个方法??
    DownUrl方法里面又有一个位于MSDAL命名空间下的DbHelperSQL类的方法:
    ExSqlReturn(string Sqlstring)
    用反射共涉及到二个方法了,这怎么用啊,
      

  5.   

    调用DownUrl即可,给了你例子,自己可以去尝试下;
    具体问题,再特殊对待;