see 
http://expert.csdn.net/Expert/topic/2488/2488470.xml?temp=.3978693这里有几个关于反射的帖子
http://www.csdn.net/Develop/Read_Article.asp?Id=15284
http://www.csdn.net/Develop/Read_Article.asp?Id=15285
http://www.csdn.net/Develop/Read_Article.asp?Id=15286

解决方案 »

  1.   

    m = t.GetMethod("GetMessage"); //可以不用参数
    m.Invoke(this,Parameters);//这里再使用参数
      

  2.   

    多谢各位参与,可是我的问题在于怎样使用带有ref和out的参数,因为参数
    ParameterModifier[] modifiers
    是来指定方法中参数的这样的属性的,可是我不知道该如何指定,所以各位没有答到我的问题所在上,请再考虑一下吧:)
      

  3.   

    m.Invoke(this,Parameters);//这里再使用参数
    比如原来调用GetMessage(AAA,BBB,CCC)是这种形式那么m.Invoke(this,AAA,BBB,CCC);明白了吗?
      

  4.   

    GetMethod并不用指定方法的参数,在Invoke执行方法时再给出参数
      

  5.   

    TO:antshome(忧郁的苦瓜)
    我知道你说的用法,可是我能用这个形式传参数吗?(带ref或out)
    m.Invoke(this,ref AAA,out BBB,CCC);
    这个m.Invoke()方法中的参数是一个object[],
    在这个object[]中的元素是传入的值,而不是一个param形式的参数,所以不能向你那样用吧.再看看吧:)
      

  6.   

    TO:antshome(忧郁的苦瓜)
    我知道你说的用法,可是我能用这个形式传参数吗?(带ref或out)
    m.Invoke(this,ref AAA,out BBB,CCC);
    这个m.Invoke()方法中的参数是一个object[],
    在这个object[]中的元素是传入的值,而不是一个param形式的参数,所以不能向你那样用吧.再看看吧:)
      

  7.   

    ParameterModifier[] argument is only used when doing late bound COM interop callsfor your purpose, you only need to do 
    Type[] paramTypes = new Type[] {Type.GetType("System.String&")};
    MethodInfo mi = typeof(TestRef).GetMethod( "GetMessage", paramTypes );tryusing System;
    using System.Reflection;class TestRef
    {
      public int GetMessage(ref string Message, out int value2)
      {
    Console.WriteLine(Message);
    Message = "123";
    value2 = 100;
    return 2;
      }  public static void Main()
      {
    TestRef tr = new TestRef();
    String s="";
    int out2;
    int i = tr.GetMessage(ref s, out out2);
    Console.WriteLine("normal way: {0}:{1}:{2}", i, s, out2); Type[] paramTypes = new Type[] {Type.GetType("System.String&"), Type.GetType("System.Int32&")};
    MethodInfo mi = typeof(TestRef).GetMethod( "GetMessage", paramTypes );
    if (mi != null)
    {
    Console.WriteLine(mi.Name); string s2 = "abc";
    object[] o = new object[2];
    o[0] =  s2;
    int i2 = (int)mi.Invoke(tr, o);
    Console.WriteLine("reflection:{0}:{1}:{2}", i2, o[0], o[1]);
    }
      }
    }
      

  8.   

    果然是 saucer(思归)^_^
    太好,经典之及!
    以前我的误区在取s2了,而不是o[0]或o[1],太谢谢了!