Since .net-6.0 the generational patterns were changed (as it was mentioned in the original feature spec, names for generated class and method are implementation depended), now the generated class name is Program
which is now covered in the spec:
The type is named "Program", so can be referenced by name from source code. It is a partial type, so a type named "Program" in source code must also be declared as partial.
But the name for the synthesized Main
method is (still) implementation depended:
But the method name "Main" is used only for illustration purposes, the actual name used by the compiler is implementation dependent and the method cannot be referenced by name from source code.
There is another thing to note - this method is an entry point of the assembly:
The method is designated as the entry point of the program. Explicitly declared methods that by convention could be considered as an entry point candidates are ignored.
So you can access it via Assembly.EntryPoint
property (so no need to rely on the name):
var assemblyEntryPoint = typeof(Program).Assembly.EntryPoint;