J
Joshua Ellul
Hi There,
Could someone tell me how I can get a class from its name?
Regards,
Josh
Could someone tell me how I can get a class from its name?
Regards,
Josh
Joshua said:(sorry for replying on your email)
Hi,
Thank for the reply... Yeah an instantiation of the class is what I
required...
However, it does not work for any classes that are in a dll..
E.g. I have a dll "netpetJ.dll" with namespace "netpetJ" with a class
"testclass"
Type t = Type.GetType("netpetJ.testclass");
the gettype function is returning null... do you know what might be the
problem?
----- Original Message -----
From: "Matt Berther" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework
Sent: Thursday, April 29, 2004 21:15
Subject: Re: get class from name
(sorry for replying on your email)
some sort of base class or interface that your classes would inherit orMatt Berther said:Hello Joshua,
No biggie, I replied to your email. I'll post my answer here for everyone elses benefit.
If it hasn't been loaded, you'll need to load the assembly.
Assembly asm = AppDomain.CurrentDomain.Load("netpetJ.dll");
Type t = Type.GetType("netpetJ.testclass");
object o = Activator.CreateInstance( t );
Not that before you can call methods on it, you'll need to cast it to the appropriate type.
If you're developing a plug-in style architecture, you'll probably want
Joshua Ellul said:Thanks a lot!!!!
I managed by looping through Assemblies attached and for each assembly each
type... then when I found the type I required I could use that type.
Thanks a Mil,
Josh
everyoneMatt Berther said:Hello Joshua,
No biggie, I replied to your email. I'll post my answer here for
elses benefit.theIf it hasn't been loaded, you'll need to load the assembly.
Assembly asm = AppDomain.CurrentDomain.Load("netpetJ.dll");
Type t = Type.GetType("netpetJ.testclass");
object o = Activator.CreateInstance( t );
Not that before you can call methods on it, you'll need to cast it to
appropriate type.some sort of base class or interface that your classes would inherit orIf you're developing a plug-in style architecture, you'll probably want
implement. At that point, you'd do something like: