Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get namespace in a static function

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) )

like image 273
Serge Wautier Avatar asked Dec 02 '09 08:12

Serge Wautier


1 Answers

Console.WriteLine(typeof(TheClassThatContainsTheStaticFunction).Namespace);

Or using reflection:

Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace);
like image 70
Darin Dimitrov Avatar answered Oct 31 '22 20:10

Darin Dimitrov