Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. using NUnit.Framework;
  5.  
  6. namespace WebApplication2
  7. {
  8.     public class Class1
  9.     {
  10.         public void callMethod(string method)
  11.         {
  12.             object classInstance = Activator.CreateInstance(typeof(THE_INHERITED_CLASS), null);
  13.             MethodInfo methodInfo = classInstance.GetType().GetMethod(method);
  14.             methodInfo.Invoke(classInstance, null);
  15.         }
  16.  
  17.     }
  18.  
  19.     public class THE_INHERITED_CLASS
  20.     {
  21.         public void MyMethod()
  22.         {
  23.             Console.WriteLine("MyMethod Called");
  24.         }
  25.     }
  26.  
  27.     [TestFixture]
  28.     public class Test
  29.     {
  30.         [Test]
  31.         public void TestItWorks()
  32.         {
  33.             Class1 class1 = new Class1();
  34.             class1.callMethod("MyMethod");
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement