❔ How can I avoid supplying redundant generic type arguments in this case.

interface IDataStructure<ItemType, LocatorType> {...}

Class MyStringArray: IDataStructure<string, int> {...}

Class Effect<D, I, L> where D : IDataStructure<I,L> {...}

new Effect<MyStringArray, string, int>();


This is what I currently have. To give some context, I have a number of custom data structures (implementing IDataStructure) and I would like Effect to be a generic class that can operate on any of them. However, I need access to the Item and Locator types of the data structure within the Effect class.

The above code works however the I and L type arguments are essentially redundant since they can be inferred from D. I would like something like class Effect<D<I,L>> where D : IDataStructure<I,L> { } (which doesn't compile) so that I can do `new Effect<MyStringArray>()' (only specifying one generic type argument but having access to the Item and Locator types within the Effect class).
Was this page helpful?