|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
dynamic class loadingIf someone has compiled a dll for the some classes, and I want to use the dll in another project, how can I know the class available in that dll file? Thanks! KC Eric -- -> ¹ª¨¬·F«l¡A¤Oª§¤W´å¡A¦h§Ö¦n¬Ù¦a«Ø³]²z·QFYP¥D¸q -> °í¨M¿í±qÄPô¥|¶µªíz¡A¥þ±¸¨¹ê¤jÄPª÷Á`¸ô½u¡A¨«¦V¥|Óª«¥óªì©l¤Æ -> ¯R¿Ë®Q¿Ë³£¤£¤Îª÷ÄPô¿Ë XDDD -> To be energetic to strive for the best. To build our FYP idealism in a flourishing, rapid, perfect and efficient manner. -> To firmly adhere to Pango's Four Statements. To comprehensively implement The Giant Pango's Great Scheme. To stride forward to the Initialization of The Four Objects. -> Parents are not as close as Pango. XDDD Assembly a = Assembly.LoadFrom(<codebase of assembly>);
foreach( Type t in a.GetTypes() ) { if( a.IsClass ) { // Do stuff to class such as object o = a.CreateInstance(t.FullName); } } Obviously if you are interested in all types not just classes you can omit the if. Regards Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk Hi all, If someone has compiled a dll for the some classes, and I want to use the dll in another project, how can I know the class available in that dll file? Thanks! Thanks!
How about even the name of the dll file is not provided? We only know the dll file is in a certain directory, say c:\temp, but the name of dll is not known. KC Eric -- -> ¹ª¨¬·F«l¡A¤Oª§¤W´å¡A¦h§Ö¦n¬Ù¦a«Ø³]²z·QFYP¥D¸q -> °í¨M¿í±qÄPô¥|¶µªíz¡A¥þ±¸¨¹ê¤jÄPª÷Á`¸ô½u¡A¨«¦V¥|Óª«¥óªì©l¤Æ -> ¯R¿Ë®Q¿Ë³£¤£¤Îª÷ÄPô¿Ë XDDD -> To be energetic to strive for the best. To build our FYP idealism in a flourishing, rapid, perfect and efficient manner. -> To firmly adhere to Pango's Four Statements. To comprehensively implement The Giant Pango's Great Scheme. To stride forward to the Initialization of The Four Objects. -> Parents are not as close as Pango. XDDD "Richard Blewett [DevelopMentor]" <richardb@NOSPAMdevelop.com> ¦b¶l¥ó omit the if.news:egA1H2eMFHA.3328@TK2MSFTNGP14.phx.gbl ¤¤¼¶¼g... > Assembly a = Assembly.LoadFrom(<codebase of assembly>); > foreach( Type t in a.GetTypes() ) > { > if( a.IsClass ) > { > // Do stuff to class such as > object o = a.CreateInstance(t.FullName); > } > } > > Obviously if you are interested in all types not just classes you can Show quote > > Regards > > Richard Blewett - DevelopMentor > http://www.dotnetconsult.co.uk/weblog > http://www.dotnetconsult.co.uk > > Hi all, > > If someone has compiled a dll for the some classes, > and I want to use the dll in another project, how can I know the class > available in that dll file? > > Thanks! > > foreach( string fileName in Directory.GetFiles(<directory path>, "*.dll")
{ try { Assembly a = Assembly.LoadFrom(fileName); // etc } catch( FileLoadException e) { // deal with the fact that some of the dlls may not be assemblies } } Regards Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk Thanks! How about even the name of the dll file is not provided? We only know the dll file is in a certain directory, say c:\temp, but the name of dll is not known. Really thanks so much !
KC Eric -- Show quote-> ¹ª¨¬·F«l¡A¤Oª§¤W´å¡A¦h§Ö¦n¬Ù¦a«Ø³]²z·QFYP¥D¸q -> °í¨M¿í±qÄPô¥|¶µªíz¡A¥þ±¸¨¹ê¤jÄPª÷Á`¸ô½u¡A¨«¦V¥|Óª«¥óªì©l¤Æ -> ¯R¿Ë®Q¿Ë³£¤£¤Îª÷ÄPô¿Ë XDDD -> To be energetic to strive for the best. To build our FYP idealism in a flourishing, rapid, perfect and efficient manner. -> To firmly adhere to Pango's Four Statements. To comprehensively implement The Giant Pango's Great Scheme. To stride forward to the Initialization of The Four Objects. -> Parents are not as close as Pango. XDDD "Richard Blewett [DevelopMentor]" <richardb@NOSPAMdevelop.com> ¦b¶l¥ó news:OLRe3ohMFHA.2680@TK2MSFTNGP09.phx.gbl ¤¤¼¶¼g... > foreach( string fileName in Directory.GetFiles(<directory path>, "*.dll") > { > try > { > Assembly a = Assembly.LoadFrom(fileName); > // etc > } > catch( FileLoadException e) > { > // deal with the fact that some of the dlls may not be assemblies > } > } > > Regards > > Richard Blewett - DevelopMentor > http://www.dotnetconsult.co.uk/weblog > http://www.dotnetconsult.co.uk > > Thanks! > > How about even the name of the dll file is not provided? > > We only know the dll file is in a certain directory, say c:\temp, but the > name of dll is not known. > |
|||||||||||||||||||||||