-------------------
From: "Petter" <wildfrog@NOSPAMspray.no>
Newsgroups: microsoft.public.dotnet.languages.csharp
If you got a class like this
namespace MyOuterNamespace
{
namespace MyInnerNamespace
{
class MyClass
{
}
}
}
then the Type.Namespace property returns the string
"MyOuterNamespace.MyInnerNamespace". Using this (and some string
manipulation) you should be able to "parse" out which namespace(s) the
type/class is nested within.
Petter
Petter is right.
In case you are still wondering what kind of string manipulation is needed,
the StartsWith() method in the String class is useful. However, if you
have two namespace strings ns1 and ns2,
ns1.StartsWith( ns2 )
will NOT always tell you whether ns1 is nested in ns2. For example, when
ns1 is "Foo.Bar" and ns2 is "Foo.B", the above expression returns true
while ns1 is not really nested in ns2.
Given that namespaces are period-separated, the following trick will solve
the problem:
(ns1 + ".").StartsWith( ns2 + ".")
HTH,
- Zhanyong Wan
Visual Studio and .NET Setup
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included samples (if any) is subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm