hy there!
given is this class:
public static class FooClass<TFoo>
{
public static TFoo FooMethod(object source)
{
// implementation goes here
}
}
now i want to create this class:
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?!
}
}
also to mention:
- there are overloads of
FooMethodinFooClass<TFoo>, but i only want to give access to mentioned overload (signature is matching – except paramterNames) - returnType
objectwould be succifient - i cannot make
FooMethodinFooClassgeneric – it should be an “oldstyle” interface, as it will be used from reflection-code
Something like:
however – this reflection can be slow in a tight loop; if you are doing this lots, I would be tempted to reverse the dependency, so the generic code calls into the non-generic code:
(with the implementation in the non-generic version)