【发布时间】:2013-02-25 08:23:08
【问题描述】:
public interface PipelineElement<in TIn, out TOut>
{
IEnumerable<TOut> Run(IEnumerable<TIn> input, Action<Error> errorReporter);
}
public interface Stage
{
}
public abstract class PipelineElementBase<TIn, TOut> : PipelineElement<object, object>,
PipelineElement<TIn, TOut> where TIn : Stage where TOut : Stage
{
IEnumerable<object> PipelineElement<object, object>.Run(IEnumerable<object> input, Action<Error> errorReporter)
{
return this.Run(input.Cast<TIn>(), errorReporter).Cast<object>();
}
public abstract IEnumerable<TOut> Run(IEnumerable<TIn> input, Action<Error> errorReporter);
}
object 没有实现Stage,因此TIn 和TOut 都不可能是object,对吧?那么为什么编译器会认为PipelineElement<object, object> 和PipelineElement<TIn, TOut> 可以变得相同呢?
编辑:是的,完全有可能多次实现同一个通用接口:
public interface MyInterface<A> { }
public class MyClass: MyInterface<string>, MyInterface<int> { }
【问题讨论】:
-
我删除了我的 cmets,我没有得到任何有用的东西。标记为收藏,我也想知道答案:)。为这个问题 +1!
标签: c# generics compiler-errors