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
nie implementuje Stage
zatem ani TIn
ani TOut
mogłoby kiedykolwiek być object
, prawda? Dlaczego więc kompilator myśli, że PipelineElement<object, object>
i PipelineElement<TIn, TOut>
może stać się identyczny?Dlaczego powoduje to CS0695?
EDIT: Tak, to jest całkiem możliwe, aby wdrożyć te same rodzajowy interfejs wielokrotnie:
public interface MyInterface<A> { }
public class MyClass: MyInterface<string>, MyInterface<int> { }
usunąłem moje komentarze, nie mam nic pożytecznego. Oznaczony jako ulubiony, chciałbym również znać odpowiedź :). +1 na pytanie! – bas