dynamic class loading

K

KC Eric

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!

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
 
R

Richard Blewett [DevelopMentor]

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!
 
K

KC Eric

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
 
R

Richard Blewett [DevelopMentor]

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.
 
K

KC Eric

Really thanks so much !

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top