如果你为泛型类实现泛型扩展方法有更好的方法吗?因为完全调用func2是很自然的,func1<V>()而不是func2<T, V>()省略T参数并将其称为func2<V>()
public class A<T> where T : class {
public V func1<V>() {
//func1 has access to T and V types
}
}
public static class ExtA {
// to implement func1 as extension method 2 generic parameters required
// and we need to duplicate constraint on T
public static V func2<T, V>(this A<T> instance) where T : class {
// func2 has access to V & T
}
}
Run Code Online (Sandbox Code Playgroud)