How to determine the entry point of a .Net program at runtime?

Let's say I have two types in my program, Fooand Bar. Both have a static void Main(string[] args). To compile this program, a compiler flag is required /main:class.

Is it possible at runtime to determine which of the two types contains an entry point, i.e. to get TypeInfoor MethodInfoby pointing me to the correct class or the correct method Main?

UPD: more precisely, is it possible to do this from the class library associated with the main application (i.e. without prior knowledge of the possible options)?

+4
source share
1 answer

The assembly has public virtual MethodInfo EntryPoint { get; }

+8
source

Source: https://habr.com/ru/post/1686752/


All Articles