//Type type = DataHelper.Instance.GetType(); //MethodInfo[] infos = type.GetMethods(BindingFlags.Instance | BindingFlags.Public); Assembly ass = System.Reflection.Assembly.LoadFrom(@"D:DBHelper.dll"); //Type type = ass.GetType("DBHelper.SqlConn"); Type type = ass.GetType("DBHelper.Datahelper", false, true); MemberInfo[] infos = type.GetMembers(); //object reflectTest = Activator.CreateInstance(type,false); //MethodInfo info = type.GetMethod("GetConn", new Type[] { typeof(string) }); //string conn = (string)info.Invoke(reflectTest, new string[] { "D" }); //string conn = DBHelper.SqlConn.GetConn("D"); //DataTable dt = DataHelper.Instance.GetDataTable("select * from C", "D");
反射窗体的代码:
Assembly ass = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "\Test.dll"); Form fr = ass.CreateInstance("Test.Form1") as Form;
Type type = Type.GetType("Test2.Form1"); Form fr = Activator.CreateInstance(type) as Form;