I asked this on SO and got skewered. I love SO for the answers, but asking a question is fraught with peril. I'm new here, but I'm hopeful y'all will be more forgiving and helpful.
if I:
and then dotnet run, I see:
Namespace: four
Class: Program
Method: Main
But if I:
and then dotnet run, I see:
Namespace:
Class: Program
Method: <Main>$
Is the code really running outside of a namespace? or is there another way to get the active namespace?
Thanks!
if I:
create a new 3.1 app:
dotnet new console -f netcoreapp3.1 -n four
add to Program.cs
Console.WriteLine("Namespace: {0}",
MethodBase.GetCurrentMethod()?.DeclaringType?.Namespace ?? string.Empty);
Console.WriteLine("Class: {0}",
MethodBase.GetCurrentMethod()?.DeclaringType?.Name ?? string.Empty);
Console.WriteLine("Method: {0}",
MethodBase.GetCurrentMethod()?.Name ?? string.Empty);
and then dotnet run, I see:
Namespace: four
Class: Program
Method: Main
But if I:
create a new 7 app:
dotnet new console -f net7.0 -n seven
add to top:
using System.Reflection;
Console.WriteLine("Namespace: {0}",
MethodBase.GetCurrentMethod()?.DeclaringType?.Namespace ?? string.Empty);
Console.WriteLine("Class: {0}",
MethodBase.GetCurrentMethod()?.DeclaringType?.Name ?? string.Empty);
Console.WriteLine("Method: {0}",
MethodBase.GetCurrentMethod()?.Name ?? string.Empty);
and then dotnet run, I see:
Namespace:
Class: Program
Method: <Main>$
Is the code really running outside of a namespace? or is there another way to get the active namespace?
Thanks!