Janus... No problem, but there are security risks.
http://www.geocities.com/jeff_louie/OOP/oop13.htm
// now dynamically load class DrawPlugIn.Tria ngle which
// implements interface MyInterface.IDr awable
Assembly assembly= null;
try
{
// tell app where to look for plugins
AppDomain.Curre ntDomain.Append PrivatePath("pl ugins");
// get absolute path to our private assemblies
string path=
AppDomain.Curre ntDomain.BaseDi rectory+"plugin s";
// create plugins folder if one does not exist
DirectoryInfo info= new DirectoryInfo(p ath);
if (!info.Exists){ info.Create();}
// discover all dlls in plugins folder
string[] dir= Directory.GetFi les(path,"*.dll ");
// iterate over files in folder plugins
foreach (string s in dir)
{
string dll= Path.GetFileNam eWithoutExtensi on(s);
assembly= Assembly.Load(d ll); // in folder
plugins
Type[] types= assembly.GetTyp es();
foreach(Type t in types)
{
Console.WriteLi ne("Type: {0}",t);
try
{
// only load if implements
IDrawable
// use fully qualified name!
if
(t.GetInterface ("MyInterface.I Drawable")!= null)
//if
(typeof(IDrawab le).IsAssignabl eFrom(t)) // safer
{
// dynamically load this
class
object obj=
Activator.Creat eInstance(t);
drawableList.Ad d(obj);
// no need to cast
}
}
catch(Exception e)
{
Console.WriteLi ne(e);
}
}
}
}
catch(Exception e)
{
Console.WriteLi ne(e);
}
Regards,
Jeff
Just wondering, is it possible to make a folder with assemblies and
have the
application to read it in runtime?<
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!