I have a question about .net generics. Consider the following code:
public abstract class Test<TKey>
{
TKey Key { get; set; }
}
public class Wrapper<TValue, TKey>
where TValue : Test<TKey>
{
public TValue Value { get; set; }
}
Now, when using this code, I could do something like this:
Wrapper<Test<int>, int> wrapper = new Wrapper<Test<int>, int>();
The int type parameter has to be provided twice. Is it possible to modify the Wrapper definition, to require TValue to be a generic type, and use this 'nested' generic type parameter insted of the TKey type parameter?
Test<TKey>could beSomethingInheritingFromTest<TKey>instead? If that's the case I don't see a way around specifying the type parameter, since you don't have a type you can feed the sameTto, since you don't know what it is, even if you created a base/wrapper...smarter generic guys here than I though, hopefully someone educates me :)