如何通过一个字符串,反射到工厂里面的类啊,谢谢!越详细越好。

解决方案 »

  1.   

    是不是:
     string classname;
     ..... Assembly assem = Assembly.LoadFrom(file);
     Type classType = assem.GetType(classname);
      

  2.   


    Type _TypeInfo = Type.GetType(FullClassName);
                object _Type = System.Activator.CreateInstance(_TypeInfo);
      

  3.   

    工厂里面超级多个类吗?如果不是建议用枚举来switch,,反射效率比较低
      

  4.   


    则么整啊?用枚举可以的话发一封邮件到我的邮箱:
    [email protected]
      

  5.   

      private static readonly string _path = System.Configuration.ConfigurationManager.AppSettings["DAL"];
            private static object GetInstance(string CacheKey)
            {
                object objType = DataCache.GetCache(CacheKey);
                if (objType == null)
                {
                    try
                    {
                        objType = Assembly.Load(DALFactory._path).CreateInstance(CacheKey);
                        DataCache.SetCache(CacheKey, objType);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                return objType;
            }
    参考