Created
July 20, 2012 12:54
-
-
Save shanefulmer/3150581 to your computer and use it in GitHub Desktop.
Dynamic Dispatch 3
This file contains 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
using System; | |
using System.Collections.Generic; | |
public class Foo { } | |
public class Bar { } | |
public class Baz { } | |
public class Program | |
{ | |
public static void CallMe<T>(T input) | |
{ | |
Console.WriteLine("typeof(T): {0}", typeof(T)); | |
} | |
static void Main() | |
{ | |
var objects = new List<object>(); | |
objects.Add(new Foo()); | |
objects.Add(new Bar()); | |
objects.Add(new Baz()); | |
foreach (var o in objects) | |
{ | |
var method = typeof(Program) | |
.GetMethod("CallMe") | |
.MakeGenericMethod(o.GetType()) | |
.Invoke(null, new object[] { o }); | |
} | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment