问题描述
Assemblyassem=Assembly.LoadFile(Path.Combine("xxx")Type[]types=assem.GetTypes();使用这两句,是不是能得到任意.net生成出来的dll里面的类?如果不是,使用的时候怎么操作?
解决方案
解决方案二:
顶下,我也正在研究这个问题,如果解决了,发出来一起学习啊,谢谢QQ420910624
解决方案三:
AssemblyLoadDll=Assembly.LoadFrom(DllName);TypeLoadClass=LoadDll.GetType("MtLib.LibTest");我是这样用的,LibTest是DLL中的类名
解决方案四:
楼上的能说的再细点么,不明白啊,那样就可以了么,生成的Type类型后怎么使用啊
解决方案五:
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Configuration;usingSystem.Reflection;namespaceConsoleApp{publicdelegatestringdele(stringstr);publicclassBmw{privatestaticintidata;privatecharcdata;publicstaticstringsdata;publicdoubleddata;publicBmw(){}publicBmw(inti){idata=i;}privateBmw(charc){cdata=c;}publiccharCdata{get{returncdata;}set{cdata=value;}}privatestringHa(){Console.WriteLine("haha");return"";}publicstringDisplay(stringstr){return"asdf";}publicvoidDrive(){Console.WriteLine("drivebmw..");}}classProgram{staticvoidMain(){//Assembly.Load().CreateInstance()Assemblya=Assembly.LoadFrom("ConsoleApp.exe");Type[]mytypes=a.GetTypes();Console.WriteLine("thesetypesareincluded...");foreach(Typetinmytypes){System.Console.WriteLine(t.Name);}Typeht=typeof(Bmw);Console.WriteLine("thesemethodsareincluded..");MethodInfo[]info=ht.GetMethods();foreach(MethodInfomininfo){Console.WriteLine(m.Name);}ConstructorInfo[]consinfo=ht.GetConstructors();Console.WriteLine(".................................................");Console.WriteLine("constructoris");foreach(ConstructorInfocinconsinfo){Console.WriteLine(c.Name);}EventInfo[]einfo=ht.GetEvents();Console.WriteLine(".................................................");Console.WriteLine("eventis");foreach(EventInfoeineinfo){Console.WriteLine(e.Name);}FieldInfo[]finfo=ht.GetFields();Console.WriteLine(".................................................");Console.WriteLine("fieldis");foreach(FieldInfofinfinfo){Console.WriteLine(f.Name);}MemberInfo[]minfo=ht.GetMembers();Console.WriteLine(".................................................");Console.WriteLine("memberis");foreach(MemberInfominminfo){Console.WriteLine(m.Name);}PropertyInfo[]pinfo=ht.GetProperties();Console.WriteLine(".................................................");Console.WriteLine("propertyis");foreach(PropertyInfopinpinfo){Console.WriteLine(p.Name);}Console.WriteLine(ht.GetMethod("Display").ToString());BmwB=newBmw();deledel=newdele(B.Display);Console.WriteLine(del("dd"));//Carcar=Drive.DriveCar("benz");//car.Drive();Console.ReadLine();//System.Collections.Generic.}}}
解决方案六:
reflectioncouldbedll,class,assemblyetc.
解决方案七:
我发了篇很简单的反射技术使用的文章,同时写了篇实际项目中的反射应用,希望对你有帮助http://blog.csdn.net/go2newlife/archive/2007/11/27/1904687.aspx