猿问

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

我正在编写一些代码,这些代码应使用不同远程对象上的通用逻辑来更新某些字段。因此,我使用给定的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();

        ...

    }

有什么想法吗?


红糖糍粑
浏览 655回答 1
1回答
随时随地看视频慕课网APP
我要回答