Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine a .Net program's entry point at runtime?

Tags:

c#

reflection

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

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

UPD: to be more precise, is it possible to do so from a class library linked to the main application (i.e., without prior knowledge of possible options)?

like image 544
Alexey Avatar asked Oct 02 '17 12:10

Alexey


1 Answers

An assembly has a public virtual MethodInfo EntryPoint { get; }

like image 111
Henk Holterman Avatar answered Sep 22 '22 01:09

Henk Holterman