Access to an inner type
Posted
by sohum
on Stack Overflow
See other posts from Stack Overflow
or by sohum
Published on 2010-06-14T15:15:10Z
Indexed on
2010/06/14
15:22 UTC
Read the original article
Hit count: 266
A colleague of mine posted a question on an internal forum which got me thinking about whether this was possible through C#. Basically, he's got an interface as follows:
public interface IProvider<T>
{
T GetT();
}
Is it possible to use something that implements that interface as a type parameter to another generic class and have access to the type T without re-specifying it? For example:
public class Foo<P> where P : IProvider<T>
{
P p;
T GetInnerT() { return p.GetT(); }
}
This does not compile, because the type T is not defined and hence can't be used as a parameter for IProvider
. Is something like this even possible? Just curious!
© Stack Overflow or respective owner