Thursday, 5 March 2009

Execute method in C# using reflection

namespace MyCompany
{
  [TestFixture]
  public class Test
  {
    [Test]
    public void Test1()
    {
      MyClass obj = new MyClass();
 
      MethodInfo m = obj.GetType().GetMethod("Test");
      m.Invoke(obj, null);
    }
  public class MyClass
  {
    public void Test()
    {
      Console.WriteLine("Test");
    }
  }
}

No comments:

Post a Comment