31
1
using System;
2
using System.Reflection;
3
4
abstract class A<T>
5
{
6
public abstract void DoSomething(string asd, T obj);
7
}
8
9
class MyClass : A<int>
10
{
11
public override void DoSomething(string asd, int obj)
12
{
13
Console.WriteLine(obj);
14
}
15
}
16
17
public class Program
18
{
19
public static void Main(string[] args)
20
{
21
Type unboundGenericType = typeof(A<>);
22
Type boundGenericType = unboundGenericType.MakeGenericType(typeof(int));
23
Type myClassType = typeof(MyClass);
24
25
object instance = Activator.CreateInstance(myClassType);
26
27
MethodInfo doSomethingMethod = boundGenericType.GetMethod("DoSomething");
28
doSomethingMethod.Invoke(instance, new object[] {"Hello", 123});
29
}
30
}
31
Cached Result
Give me a number
>