Re: how do you find the root namespace at runtime?

From: Bob (noone_at_nowhere.com)
Date: 11/04/04


Date: Thu, 4 Nov 2004 14:52:42 -0500

You mean something like this -

Dim asm As [Assembly] = System.Reflection.Assembly.GetEntryAssembly
MsgBox(asm.EntryPoint.DeclaringType.Namespace)

But there is no guarantee that the assembly's startup object is not
contained within a deeper namespace than the root.

Um... hmmm. I guess this will work if I make sure to exclude any types from
referenced assemblies (not shown). The shortest Namespace will probably be
the root. Ugh, but again no guarantee...

Dim asm As [Assembly] = '<some assembly>
Dim Root As String
For Each t As Type In asm.GetTypes
    If Root Is Nothing Then
        Root = t.GetType.Namespace
    Else
        If Root.Length > t.FullName.Length Then
            Root = t.FullName
        End If
    End If
Next
MsgBox(Root)

I guess I'll have to call this good enough.

Thanks,
Bob

"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:u9JJ22owEHA.2016@TK2MSFTNGP15.phx.gbl...
> Bob,
> Have you tried using my second example?
>
> For example to get the namespace of the main form class, you can use:
>
> Dim [namespace] As String = GetType(MainForm).Namespace
>
> MainForm is the name of your startup object (as set in Project
Properties).
>
> Hope this helps
> Jay
>
>
>
> "Bob" <noone@nowhere.com> wrote in message
> news:uyU9blowEHA.1260@TK2MSFTNGP12.phx.gbl...
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in
message
> > news:%23uUwepcwEHA.2624@TK2MSFTNGP11.phx.gbl...
> >> Bob,
> >> > how do you find the root namespace at runtime?
> >> Root namespace of what?
> >
> > The project that created the currently executing assembly.
> >
> > In the property pages of a project, available by right-clicking one one
> > and
> > selecting 'properties', under 'common properties'/'general' there is a
> > place
> > you can enter a 'Root Namespace'. I would like access to this at
runtime.
> >
> > Bob
> >
> >
>
>



Relevant Pages

  • Re: how do you find the root namespace at runtime?
    ... > contained within a deeper namespace than the root. ... Then don't use the startup object, use a different class that is not ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Cannot find root element in XML file
    ... thingy for querying the root node. ... The nodes in the XML file aren't ... which means any child or descendant elements are in that namespace too ... xmlns attribute. ...
    (microsoft.public.dotnet.xml)
  • Re: Cannot find root element in XML file
    ... If instead of querying the 'IncidentDefinitions' root element I use ... If those child or descendant elements are in the namespace ... Makes me wonder how I support both types of XML files, ...
    (microsoft.public.dotnet.xml)
  • Re: Help: I cannot selectNodes with a simple XPath expression
    ... % [dom parse $xml] documentElement root ... So without an anonymous namespace, ...
    (comp.lang.tcl)
  • Re: Cannot find root element in XML file
    ... You have not even bothered to show the contents of the root element ... which means any child or descendant elements are in that namespace too ... What I notice is that using the XPath expressions for the XML file ... xmlns attribute. ...
    (microsoft.public.dotnet.xml)