I have a quite simple design:
a generic interface IElement<>
with a single generic parameter T
:
interface IElement<T>
{
}
ISource<>
that manages IElement<>
In ISource<>
I have a method that returns the underlying type of IElement<>
:
T GetSomething();
Here is what I can do:
interface ISource<TElem, T>
where TElem : IElement<T>
{
T GetSomething();
}
class IntegersSource : ISource<IElement<int>, int>
{
public int GetSomething()
{
return 1;
}
}
But the nested type, here int
, has to be repeated.
I'd like something like:
class IntegersSource : ISource<IElement<int>>
{
public int GetSomething()
{
return 1;
}
}
I've tried :
interface ISource<TElem>
where TElem : IElement<T>
{
T GetSomething();
}
But the compiler is not happy with this syntax.
I fear I'm missing something obvious, but what?
Thanks for any insight.
That won't work. Image you have the following class:
class MultiElement : IElement<int>, IElement<double>
{
// explicit interface implementations of IElement<int> and IElement<double> here.
}
Now when I declare a class MySource : ISource<MultiElement>
, what should be inferred as T
?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments