Click to See Complete Forum and Search --> : [RESOLVED] [1.0/1.1] Enumerating classes
nebulom
Aug 1st, 2006, 07:26 PM
How can I enumerate classes on a certain namespace?
Thanks in advance!
jmcilhinney
Aug 1st, 2006, 07:51 PM
You can't necessarily do that because a namespace is not a physical thing, but a logical one. One namespace can be spread over multiple assemblies and you have to have a reference to an assembly to see what types it contains. That means that you'd have to reference every assembly to see if it contained members of the namespace you were interested in. You can get all the types contained in an assembly using the Assembly.GetTypes method. You can then filter that result manually to exclude all types that are not classes and do not belong to the namespace of interest. That doesn't mean that that namespace doesn't have other members in another assembly though.
nebulom
Aug 1st, 2006, 08:42 PM
Thanks JM, I do have this code
[TestFixture] public class Class2
{
public Class2() {}
[Test] public void foo()
{
Assembly a = Assembly.Load("mscorlib.dll");
if (a != null)
{
foreach (Type t in a.GetTypes())
Console.WriteLine(t.FullName);
}
}
}
I need help on testing the Type I get is a Class, Interface, Enumeration or something like that... Can anyone help? Thanks!
jmcilhinney
Aug 1st, 2006, 08:59 PM
If you want to know something about a Type object where's the first place you should look? The members of the Type class.
nebulom
Aug 1st, 2006, 09:47 PM
Ok, thanks! Never been into much of Reflection, so sorry if I bother someone. Again, thanks!
mendhak
Aug 2nd, 2006, 03:57 AM
You can modify this:
http://www.vbforums.com/showthread.php?t=306850
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.