This works:
using System;
using System.Reflection;
namespace ConsoleApplication7
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Assembly ours = Assembly.GetCallingAssembly();
Type type = ours.GetType("ConsoleApplication7.Class1");
MethodInfo mi = type.GetMethod("WriteLine");
mi.Invoke(type, null);
}
public static void WriteLine()
{
Console.WriteLine("Foobar");
}
}
}
Thanks,
Shawn Wildermuth
[EMAIL PROTECTED]
> -----Original Message-----
> From: dotnet discussion [mailto:[EMAIL PROTECTED]]
> On Behalf Of Nischal Chitta
> Sent: Monday, April 15, 2002 3:15 PM
> To: [EMAIL PROTECTED]
> Subject: [DOTNET] Invoke Static method on a class using Reflection??
>
>
> Hi All
>
> Can someone help me in invoking a static method of my class
> using reflection?
>
> I have a class A, which has a static method M1(). I want to
> invoke this method at runtime without instantiating the class
> using Reflection. How can I do it??
>
> Pointer to any resource also will be really appreciated.
>
> Thanks
> Nischal
>
> You can read messages from the DOTNET archive, unsubscribe
> from DOTNET, or subscribe to other DevelopMentor lists at
> http://discuss.develop.com.
>
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.