[Reflection] Is it possible to Invoke a static method?

G

[Gauthier]

Hi,

Is it possible to invoke a System.Reflection.MethodInfo that reference a
static method?

If no, is there any other way (via reflection) to invoke a static method?

Thanks

Gauthier
 
E

Eric Cadwell

Sure...

Type t = typeof(CustomType);
if (t!= null)
{
foreach (MethodInfo mi in t.GetMethods(BindingFlags.Static |
BindingFlags.Public))
{
Console.WriteLine("method {0}", mi.Name);
mi.Invoke(null, null);
}
}

HTH;
Eric Cadwell
http://www.origincontrols.com
 
G

[Gauthier]

Hi, it works nicefully, thanks!

Gauthier

| Sure...
|
| Type t = typeof(CustomType);
| if (t!= null)
| {
| foreach (MethodInfo mi in t.GetMethods(BindingFlags.Static |
| BindingFlags.Public))
| {
| Console.WriteLine("method {0}", mi.Name);
| mi.Invoke(null, null);
| }
| }
|
| HTH;
| Eric Cadwell
| http://www.origincontrols.com
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top