You need to do:
public class EnumerableDisposer<T, J> : IDisposable where T : IEnumerable<J> where J : IDisposable { // Implement...
Unfortunately, in order to wrap any internal type ( IEnumerable<J> in your code), your "wrapping" class must have type J defined in the general definition. Also, to add an IEnumerable<J> constraint, you need to have a different type T
If you want to avoid the dual generic type specification, you can always rework it as follows:
public class EnumerableDisposer<T> : IDisposable where T : IDisposable { public EnumerableDisposer(IEnumerable<T> enumerable) {
This forces you to build it using IEnumerable<T> , where T is IDisposable, with one common type. Since you are effectively adding an IEnumerable<T> constraint through the constructor, this will work the same as the previous option. The only drawback is that you need the overall result to be executed during construction, but given the name, I suspect that everything will be fine ...
Reed copsey
source share