I'd like to print the namespace of the currently executing code running in .NET 7 using C#.
Something akin to:
Inside of Main (in Program.cs of a program called myApp):
// See https://aka.ms/new-console-template for more information
Console.WriteLine(ns);
expected output: myApp
...the namespace of the program.
by way of background, prior to .NET 6, a program like myApp would look like this:
using System;
namespace myApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
In order to better understand what's going on, I'm trying to determine where my code lives using reflection (indeed I read Top-level statements on the Microsoft site, but I'm interested in that "an implementation detail that your code can't reference directly").