public static class FooClass<TFoo>
{
public static TFoo FooMethod(object source)
{
// implementation goes here
}
}
现在我要创建这个类:
public static class FooClass
{
public static object FooMethod(object source, Type fooType)
{
var classType = typeof (FooClass<>).MakeGenericType(fooType);
var methodInfo = classType.GetMethod("FooMethod", new[]
{
typeof (object)
});
// WHAT NOW?!
}
}
public static class Foo
{
public static object FooMethod(object source, Type fooType)
{
return typeof(Foo<>).MakeGenericType(fooType)
.GetMethod("FooMethod").Invoke(null, new object[] { source });
}
}