Results 1 to 6 of 6

Thread: [RESOLVED] [1.0/1.1] Enumerating classes

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: [1.0/1.1] Enumerating classes

    Ok, thanks! Never been into much of Reflection, so sorry if I bother someone. Again, thanks!

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width