Type type = Type.GetType(类名字符串); object instance = Activator.CreateInstance(type);
Type.GetType(类名字符串) 类名字符串 应该是 名称空间.类名
再up(如何实例化一个Form?)
'在同一个工程中,添加两个Form,然后在其中一个Form中显示另外一个 System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); Form f = (Form)assembly.CreateInstance("winApp_cs.Form2"); f.ShowDialog();
Assembly ass = Assembly.LoadFrom(@"E:\MainHR.DAL.SQL.dll"); Type t = ass.GetType("MainHR.DAL.SQL.SQLDB"); ConstructorInfo conInfo = t.GetConstructor(Type.EmptyTypes); this.aSQLDB = (MainHR.Common.IDataBase)conInfo.Invoke(null);
System.Reflection.ConstructorInfo mc_cnt_info=type.GetConstructor();
Object obj=mc_cnt_info.Invoke();
Thank u!
object instance = Activator.CreateInstance(type);
类名字符串 应该是 名称空间.类名
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Form f = (Form)assembly.CreateInstance("winApp_cs.Form2");
f.ShowDialog();
Type t = ass.GetType("MainHR.DAL.SQL.SQLDB");
ConstructorInfo conInfo = t.GetConstructor(Type.EmptyTypes);
this.aSQLDB = (MainHR.Common.IDataBase)conInfo.Invoke(null);
[email protected]