我想在另一个泛型类型中使用泛型类型。
但得到以下异常:
该类型
'MockManagers.ToPos'
不能用作'Res'
泛型类型或方法中的类型参数'MockManagers.IMockManager<Req,Res>'
。没有从'MockManagers.ToPos'
到的隐式引用转换'MockManagers.MockResponseObject<System.IComparable>'
。
我尝试了几个选项来解决这个问题,但没有任何运气。此参考建议将内部泛型类型作为参数传递给更高级别的泛型类型。这是唯一的解决方案吗?
代码:
我的界面:
/// <summary>
/// Represents IMockManager for mock object creation object.
/// </summary>
/// <typeparam name="Req">The request object Type.</typeparam>
/// <typeparam name="Res">The response object type.</typeparam>
public interface IMockManager<Req, Res>
where Req : MockRequestObject
where Res : MockResponseObject<IComparable>
{...//interface definitions}
对象实现:
/// <summary>
/// Represents Mock response for a request object
/// </summary>
public class ToPos : MockResponseObject<byte[]>
{... //implementation}
public class MockBaseObject
{
public int Id { get; set; }
}
public class MockResponseObject<T> : MockBaseObject
{
/// <summary>
/// The response content.
/// </summary>
public T Content { get; set; }
/// <summary>
/// Res creation date.
/// </summary>
public DateTime CreationDate { get; set; }
}