|
-
Aug 1st, 2006, 07:26 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [1.0/1.1] Enumerating classes
How can I enumerate classes on a certain namespace?
Thanks in advance!
Last edited by Hack; Aug 8th, 2006 at 11:09 AM.
Reason: Added [RESOLVED] to thread title Last edited by nebulom : 08-01-2006 at 10:47 PM.
-
Aug 1st, 2006, 07:51 PM
#2
Re: [1.0/1.1] Enumerating classes
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.
-
Aug 1st, 2006, 08:42 PM
#3
Thread Starter
Fanatic Member
Re: [1.0/1.1] Enumerating classes
Thanks JM, I do have this code
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!
-
Aug 1st, 2006, 08:59 PM
#4
Re: [1.0/1.1] Enumerating classes
If you want to know something about a Type object where's the first place you should look? The members of the Type class.
-
Aug 1st, 2006, 09:47 PM
#5
Thread Starter
Fanatic Member
Re: [1.0/1.1] Enumerating classes
Ok, thanks! Never been into much of Reflection, so sorry if I bother someone. Again, thanks!
-
Aug 2nd, 2006, 03:57 AM
#6
Re: [1.0/1.1] Enumerating classes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|