比如说 test1 对应着  test1.cs 这个公共类
          test2 对应着  test2.cs 这个公共类       如果我接收到test1 则调用test1.cs   接收到test2 则调用test2.cs        请问能如何做到? 
       

解决方案 »

  1.   

    Type wantType = System.Reflection.Assembly.GetCallingAssembly().GetType( class name, false, true);
    var obj = Activator.CreateInstance(wantType, null) as ActionHandler;
     
      

  2.   

    这里错了,应该是
    var obj = Activator.CreateInstance(wantType, null);
      

  3.   

    我有个朋友说  用接口和 多态  能做  请问可以吗?   我要调用的类里面的方法 是public的
      

  4.   

    string input = "";
    input = 你希望的值test1或者test2;
    Type t = Type.GetType(input, true, true);
    //利用晚期绑定建立晚期绑定类型的实例
    object obj = System.Activator.CreateInstance(t);//一,调用无参数方法
    MethodInfo mi = t.GetMethod(方法名);
    mi.Invoke(obj, null);//二,调用有参数方法
    object[] paramArray = new object[参数个数,假定2个];
    paramArray[0] = 参数1;
    paramArray[1] = 参数2;
    MethodInfo mi = t.GetMethod(有参数方法名);
    mi.Invoke(obj, paramArray);