Advertisement
Guest User

Finding generic method

a guest
May 27th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5.  
  6. namespace tacGenericTest
  7. {
  8.     [TestClass]
  9.     public class GetMethodTest
  10.     {
  11.         [TestMethod]
  12.         public void FindMethodTest()
  13.         {
  14.             var methodInfo = typeof (GenericMethodContainer).GetMethod("Test", BindingFlags.Static | BindingFlags.Public);
  15.             Assert.IsNotNull(methodInfo);
  16.             Assert.AreEqual("Test", methodInfo.Name);
  17.             Assert.AreEqual("DateTime", methodInfo.MakeGenericMethod(typeof(DateTime)).Invoke(null, new object[0]));
  18.         }
  19.     }
  20.  
  21.     public class GenericMethodContainer
  22.     {
  23.         public static string Test<T>()
  24.         {
  25.             return typeof(T).Name;
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement