Resolving current namespace

  • Thread starter Thread starter Glen
  • Start date Start date
G

Glen

Hi,

Is there a way to resolve the current namespace in a static method, such as
Main() from within a console app?

In a public method from a class instance, you can use the "this" keyword in
(this.GetType().Namespace) to resolve the namespace, but you can't do that
from within a static method.

Any ideas?
 
Is there a way to resolve the current namespace in a static method, such
as
Main() from within a console app?
Since you're doing this from withing the class you know the class name and
therefore you can use typeof.

namespace MyNamespace {
public class MyClass
{
public static void Main()
{
Console.Write(typeof(MyClass).Namespace);
}
}
}

This will work with dynamic methods as well.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
That did the trick. Thanks!

- Glen

Anders Norås said:
Since you're doing this from withing the class you know the class name and
therefore you can use typeof.

namespace MyNamespace {
public class MyClass
{
public static void Main()
{
Console.Write(typeof(MyClass).Namespace);
}
}
}

This will work with dynamic methods as well.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Back
Top