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>
可以變得相同?爲什麼這會導致CS0695?
編輯:是的,這是完全有可能在同通用接口多次來實現:
public interface MyInterface<A> { }
public class MyClass: MyInterface<string>, MyInterface<int> { }
我打消了我的意見,我沒有什麼用處。標記爲最喜歡的,我想知道答案以及:)。 +1的問題,雖然! – bas 2013-03-09 23:19:04