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!