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)
)
Console.WriteLine(typeof(TheClassThatContainsTheStaticFunction).Namespace);
Or using reflection:
Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With