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> { }