using System.Reflection;MethodInfo mi = YourObject.GetType().GetMethod(metName);
if (mi != null)
  mi.Invoke(YourObject, null);

解决方案 »

  1.   

    yes,agree to saucer!
    A simple demo here://class defined here
    public class LateBindingTest
    {
    public string GetSomewhat()
    {
    return "hello,fqq!";
    }
    }//below is the test codeType t = Type.GetType("PerfDemo.LateBindingTest");
    MethodInfo mi = t.GetMethod("GetSomewhat");
    object s2 = mi.Invoke(lbt,null);
      

  2.   

    http://www.yesky.com/SoftChannel/72342371928637440/20030102/1646682_1.shtml
      

  3.   

    public delegate void TestHandle();private void RunTest(bool b)
    {
    TestHandle handle   = null;
    if(b)
    handle         = new TestHandle(Test1);
    else
    handle         = new TestHandle(Test2); handle();
    }
      

  4.   

    to 楼上的,如果这个class有100个方法,你的代码怎么写?100个case?或者if/else?delegate作这个不大合适,class间进行消息的传递、流转,才是delegate最合适的。
      

  5.   

    to juqiang(方枪枪(正在修炼伤心小箭)) 
    那样的话就要用反射了,呵呵
      

  6.   

    try
    {
    Type t = Type.GetType(FormName);
    //利用System.Type的实例成员函数GetConstructor获得你需要的窗体类型的构造函数。
    System.Reflection.ConstructorInfo myConstructorInfo = t.GetConstructor(new Type[0]);
    //根据构造函数的参数列表信息获得相应的目标窗体类型的实例。
    object obj = myConstructorInfo.Invoke(new object[0]);
    //将获得的实例转换为Form类型。
    System.Windows.Forms.Form newfrm = ((Form)obj);
    newfrm.Tag =newfrm.Name ;
    newfrm.MdiParent = this.MdiParent ;
    newfrm.Show();
    }
    catch(NullReferenceException)
    {
    MessageHandle.ErrorMsgBox ("表单名称设置错误,请与管理员联系!");
    return;
    }
      

  7.   

    我讨厌一切与idispatch相关或相似的问题,这样的设计有什么意义呢,如果调用者没有足够的关于调用改方法的信息他如何实现调用呢,如果在某个情况下调用信息又是能够确定的,为什么又不使用基于oo的多态呢。使用基于oo的多态是好的多的设计习惯,强烈建议大家使用oo方法来解决各种动态问题,使用这种动态调用方法如果养成习惯的话,绝对不是好的设计风格。
      

  8.   

    MethodInfo a = objectinstance.GetType().GetMethod(methodname);
    if (a != null)
      a.Invoke(objectinstance, null);