Пример #1
0
    static void Main(string[] args)
    {
        SampleClass.Foo <int>(param =>
        {
        });
        var discoveredTypes = new List <Type>
        {
            typeof(DerivedOne),
            typeof(DerivedTwo),
            typeof(DerivedThree)
        };

        foreach (var type in discoveredTypes)
        {
            var methodType   = typeof(Program).GetMethods().FirstOrDefault(x => x.Name == "CreateMethod").MakeGenericMethod(type);
            var method       = methodType.Invoke(null, null);
            var staticMethod = typeof(SampleClass).GetMethods().FirstOrDefault(x => x.Name == "Foo").MakeGenericMethod(type);
            staticMethod.Invoke(null, new object[] { method });
        }
        Console.ReadKey();
    }