說我有以下接口C#多級泛型接口
using System;
public interface IInput
{
}
public interface IOutput<Shipper> where Shipper : IShipper
{
}
public interface IShipper
{
}
public interface IProvider<TInput, TOutput>
where TInput : IInput
where TOutput : IOutput<IShipper>
{
}
我能夠創建以下類別:
public class Input : IInput
{
}
public class Shipper : IShipper
{
}
public class Output : IOutput<Shipper>
{
}
我試過多種方法來創建實施IProvider帶班沒有運氣?
例:
public class Provider : IProvider<Input, Output>
{
}
Error: The type 'Output' cannot be used as type parameter 'TOutput' in the generic type or method 'IProvider<TInput,TOutput>'. There is no implicit reference conversion from 'Output' to 'IOutput<IShipper>'
或
public class Provider : IProvider<Input, Output<IShipper>>
{
}
Error: The non-generic type 'Output' cannot be used with type arguments
我怎樣才能做到這一點?
要遵循慣例,'IOutput'的定義中的'發貨人'應該是'TShipper'。 –
2014-09-12 17:45:57