tags:

views:

25

answers:

1

Hi All,

In an instance method, I can easily find the executing namespace:

public void PrintNamespace()
{
  Console.WriteLine(this.GetType().Namespace);
}

Q: How do I do the same in a static function (no this available) without explicitely mentioning the class name? (no typeof(MyClass) )

+2  A: 
Console.WriteLine(typeof(TheClassThatContainsTheStaticFunction).Namespace);

Or using reflection:

Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace);
Darin Dimitrov
Ah yes, I should have been more explicit about not wanting the first solution. The 2nd one is what I was looking for. Thanks!
Serge - appTranslator