用Type("域名空间加类"),但具体方法忘了,这会在网吧,所以手头上没有现成的代码给你,每个对象都有Type这个属性,楼主的想法可以实现,看看资料吧

解决方案 »

  1.   

    Proxy <t>.DoWork();  //这句无法通过编译 
    当然不通过,public class Proxy <TInterface> 
    因为你要为TInterface制定一种类型,你传入的是一个字符串Proxy<sting>.DoWork();
      

  2.   

    Proxy <t>.DoWork();  <t>这里应该是一种类型,而不是实例Proxcy<String>.DoWork();
      

  3.   

    说的很对,但是我想要知道的就是如何在这个地方把一个字符串的运行时转换为“TInterface”类型,因为运行时系统只能得到字符传变量。
      

  4.   

    使用反射,类似下面的代码Type tempObj_Type = tempObj.GetType();
    Type Nodes_type = typeof(hyFrameWork.Win.TreeNode<>);
    Type geType = Nodes_type.MakeGenericType(tempObj_Type);
    ConstructorInfo ci = geType.GetConstructor(new Type[] { });
    object oldlist = ci.Invoke(null);
      

  5.   

    能否具体些,本人对反射不是很清楚,是这样引用吗?
    Type tempObj_Type = t.GetType(); 
    Type Nodes_type = typeof(Proxy<>); 
    Type geType = Nodes_type.MakeGenericType(tempObj_Type); 
    ConstructorInfo ci = geType.GetConstructor(new Type[] { }); 
    object oldlist = ci.Invoke(null);Proxy <oldlist>.DoWork();  
    好像也不对.
      

  6.   

    Type temp = type.GetType(t); temp myinstance=new temp();
    Proxy <myinstance>.DoWork();  //
      

  7.   

    能具体点吗?是否是这个需求在framework 3.5 无法实现.另外下面是行不通的.
      

  8.   

    Type t = typeof(Proxy<>).MakeGenericType(typeof(string));
    MethodInfo m = t.GetMethod("F");
    m.Invoke(null, null);
      

  9.   

    <T> GetData(string s)
    T:struct
    {
      T t=defalut(T);
      switch(s)
      {
        case "hi":
         int i = 123;
         object o=(object) i;
         t=(T)o;//o as T;
         break;
        case "hii":
         float j=123.123;
         object o2=(object) j;
         t=(T)o2;
      }
      return t;
    }void App(){
       int i=GetData<int>("hi");
       float j=GetData<float>("hii");
    }//这个例子好象有些地方有点设计不好,但我一下说不出来是那里,我上面说的意思就是这个