Using generic type from other generic parameter

Posted by DEHAAS on Stack Overflow See other posts from Stack Overflow or by DEHAAS
Published on 2010-06-05T21:10:36Z Indexed on 2010/06/05 21:12 UTC
Read the original article Hit count: 150

Filed under:
|
|

Hi,

I have a question about .net generics. Consider the following code:

public 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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET