为了账号安全,请及时绑定邮箱和手机立即绑定

类型“ T”必须是引用类型,才能在通用类型或方法“ QueryAPI.Query <T>()

类型“ T”必须是引用类型,才能在通用类型或方法“ QueryAPI.Query <T>()

C#
红糖糍粑 2021-05-05 13:12:43
我正在编写一些代码,这些代码应使用不同远程对象上的通用逻辑来更新某些字段。因此,我使用给定的API。测试类是我自己的实现。该API提供了其他两个类。当我编写以下代码时,我得到了错误The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'QueryAPI.Query<T>()代码: public class Test<T> where T : class, UnicontaBaseEntity    {        private async Task Foo<T>(QueryAPI queryAPI, CrudAPI crudAPI, SyncSettings syncSettings)        {            Task<T[]> result = await queryAPI.Query<T>();        }    }    public interface UnicontaBaseEntity : UnicontaStreamableEntity    {        int CompanyId { get; }        Type BaseEntityType();    }    public class QueryAPI : BaseAPI    {        ...        public Task<T[]> Query<T>() where T : class, UnicontaBaseEntity, new();        ...    }有什么想法吗?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 654 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信