Created
February 27, 2018 06:04
-
-
Save mishrsud/d080307ad02f4f935deb7ddf7f3b9fd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main() | |
| { | |
| var str = "Hello"; | |
| var integer = 23; | |
| System.Reflection.MethodInfo methodDefinition = typeof(GenericClass).GetMethod("PrintName"); | |
| System.Reflection.MethodInfo method = methodDefinition.MakeGenericMethod(integer.GetType()); | |
| method.Invoke(new GenericClass(), new object [] {integer}); | |
| } | |
| // Define other methods and classes here | |
| public class GenericClass | |
| { | |
| public void PrintName<T>(T param) | |
| { | |
| System.Console.WriteLine($"Called with type: {typeof(T).Name}, value: {param}"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment