Home All Groups Group Topic Archive Search About

retreiving namespace using Reflection | Beginners

Author
18 May 2006 9:04 PM
Erland
Hi,

I want to retreive different namespaces available within an Assembly
using Reflection. Is this possible? Can i retreive a namespace within
an Assembly using " Type " ?

My question is how can we retreive a namespace from an Assembly? For
example, i can see different namespaces with " mscorlib" assembly then
how can retreive namespaces within mscorlib?
Pardon my ignorance and please enlighten me.
Thanks in advance.
-Erland

Author
18 May 2006 10:21 PM
Galcho[MCSD.NET]
take a look here
http://msdn2.microsoft.com/en-us/library/system.reflection.assembly.gettypes.aspx

you can get name of returned types' FullName property (as you know it
will start with Namespace) you can perform custom parsing to get what
you need

this is the code for getting all types in executing assembly - you must
have windows forms applciation with TextBox  called textBox1 (Multiline
property is set to true)
System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();

            Type[] types = asm.GetTypes();
            for (int i = 0; i < types.GetLength(0); i++)
            {
                textBox1.Text = string.Format("{0}{1}{2}",
textBox1.Text, types[i].FullName, Environment.NewLine);

            }

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

Bookmark and Share