编辑: 也许这是一个更清晰,更对这个问题的角度制定:差异在返回类型
在一些通用接口IInterface<T>
,我想回到一个泛型类型的对象,其中一个的类型参数应该是IInterface<T>
的实现。
public class OtherType<T> {}
public interface IInterface<T>
{
OtherType<IInterface<T>> Operation();
}
public class Impl : IInterface<int>
{
public OtherType<IInterface<int>> Operation()
{
return new OtherType<Impl>();
}
}
由于Impl
工具IInterface<int>
,它似乎是合理的,我认为我可以使用这种方式。然而,似乎我不能,我得到的编译器错误
无法转换表达式类型
OtherType<Impl>
到返回式OtherType<IInterface<int>>
请问您能否将您非常漫长而令人困惑的类名转换为A,B,C等类似的东西? – Sebastian 2013-03-27 08:39:14
@CarlPett:你是否一直关注Eric Lippert在Monads上的精彩博客系列? http://ericlippert.com/2013/02/21/monads-part-one/看来你正在努力重新发明这个构造,并且可以对一般机制有所了解。 – 2013-03-27 08:55:16
@PieterGeerkens:我没有,谢谢你的提示!看起来很有趣。我只有时间阅读前四部分,但到目前为止,我真的不知道如何在这里应用它? – carlpett 2013-03-27 16:37:17