Is it possible to have a generic constraint which is an unbounded generic type?
For example:
public T DoSomething<T>(T dictionary) where T : IDictionary<,>
{
...
}
Edit: Just to explain the context, I want to constrain the usage of the method to an IDictionary, but for the method itself it does not matter exactly what TKey and TValue are.
This isn't possible, you need to specify the type parameters:
public T DoSomething<T, TKey, TValue>(T dictionary) where T : IDictionary<TKey, TValue> { ... }
There is an issue in rosylin github, however, it's not done yet. So it's not possible right now, but I expect it will be relatively soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With