C# 工厂

 /// <summary>
        /// 创造实例
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="assemblyString">程序集名称</param>
        /// <param name="typeName">类的全名</param>
        /// <param name="parameters">构造函数参数</param>
        /// <returns></returns>
        public T Creatobject<T>(string assemblyString, string typeName, Object[] parameters)
        {
            try
            {
                return (T)System.Reflection.Assembly.Load(assemblyString).CreateInstance(typeName, true, System.Reflection.BindingFlags.Default, null, parameters, null, null);
            }
            catch (Exception ex) {
                string s = ex.Message;
            }
            return default(T);
        }
        public object Creatobject(string assemblyString, string typeName)
        {
            try
            {
                return System.Reflection.Assembly.Load(assemblyString).CreateInstance(typeName);
            }
            catch (Exception ex) { }
            return null;
        }

 

posted @ 2015-12-24 11:16  点点_滴滴  阅读(156)  评论(0编辑  收藏  举报