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");
    }
  }
}

Comments

Popular posts from this blog

Parse XML to dynamic object in C#

C# Crop white space from around the image