使用继承接口的类型约束会产生隐式引用转换错误

问题描述 投票:0回答:1

我有此类型约束

where TLookup : ILookupable<ILookup>

并且我正在为此类型传递此接口

public interface IEmployeeProxy : ILookupableCode

您在哪里

public interface ILookupableCode : ILookupable<ILookupCode>

public interface ILookupable<T> where T : ILookup
{
    Task<IEnumerable<T>> LookupByNameAsync(string name, int take = 5, int skip = 0);

    Task<T> LookupByIdAsync(long id);
}

public interface ILookupCode : ILookup

但是我遇到了There is no implicit reference conversion错误,我不知道为什么,因为对我来说IEmployeeProxy

IEmployeeProxy =>ILookupableCode=>ILookupable<ILookupCode>=> ILookupable<ILookup>

我在这里做错了什么?为什么我收到此错误?对我来说,我应该工作。

[如果您想知道为什么要这样做,是因为我想让ILookupable带有一些返回ILookup的方法,但也希望ILookupableCode带有与ILookupable相同的方法,这些方法将返回[ C0]和其他一些内容。

c# constraints type-constraints
1个回答
0
投票
唯一的解决方法是使用Task<T>
© www.soinside.com 2019 - 2024. All rights reserved.