我自定义了一个用户类 pd_user 
然后通过 
// 获得“类”类型 
Type myType =Type.GetType(“pd_user”); 
 // 实例化类 
Object o_Instance=System.Activator.CreateInstance(myType) 
但是 myType总返回null

解决方案 »

  1.   


    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.Type type = Type.GetType("ConsoleApplication1.User");
                Object obj = System.Activator.CreateInstance(type);
            }
        }    public class User
        {
            private string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }
    }
    你的pd_user  要有完整的名称 包括命名空间
      

  2.   


    我说明一下,我的MODEL申明是在一个另外单独的DLL里
    我写的时候,已经把完整的命名空间都写上去了,还是不行
      

  3.   

    那你就用Assembly反射来实现吧   网上类似的例子很多的。
      

  4.   

    Assembly.Load(path).CreateInstance(className)
    path是DLL的路径  
    className是类的完整名(包括命名空间)
    可参考PetShop4.0中的DALFactory项目