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; }
欢迎指正:haizi2014@qq.com