Calling a static method on a generic type parameter
- by Remi Despres-Smyth
I was hoping to do something like this, but it appears to be illegal in C#:
public Collection MethodThatFetchesSomething<T>()
where T : SomeBaseClass
{
return T.StaticMethodOnSomeBaseClassThatReturnsCollection();
}
I get a compile-time error: "'T' is a 'type parameter', which is not valid in the given context."
Given a generic type parameter, how can I call a static method on the generic class? The static method has to be available, given the constraint.