Alexey Alexey - 2 years ago 159
C# Question

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

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)?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download