我很难理解我的问题在这里是什么. CS0452 error, The type T must be ref type in order to use as a parameter...

错误在此行上: Response<T> tableEntity = TC.GetEntity<T>(pk, rk);

using Azure;
using Azure.Data.Tables;

namespace AzureDataTables
{
    public class AzureDataTables<T> : IAzureDataTables<T> where T : class, ITableEntity, new()
    {
        ITableEntity GetTableEntity(string pk, string rk);
    }

    public class AzureDataTables<T> : IAzureDataTables<T> where T : ITableEntity, new()
    {
        public T GetTableEntity(string pk, string rk)
        {
            var tableEntity = TC.GetEntity<T>(pk, rk);
            return tableEntity.Value;
        }
        public TableServiceClient TSC { get; set; } = new TableServiceClient("");
        public TableClient TC => TSC.GetTableClient("");
    }
}

推荐答案

如果接口的协定中有泛型类型,则需要在接口的实现中使用具体类型.下面是一个实用的示例:

using Azure;
using Azure.Data.Tables;

namespace AzureDataTables
{
    public interface IAzureDataTables<T> where T : class, ITableEntity, new()
    {
        ITableEntity GetTableEntity(string pk, string rk);
    }

    public class AzureDataTables<T> : IAzureDataTables<T> where T : class, ITableEntity, new()
    {
        public ITableEntity GetTableEntity(string pk, string rk)
        {
            Response<T> tableEntity = TC.GetEntity<T>(pk, rk);
            return tableEntity.Value;
        }

        public TableServiceClient TSC { get; set; } = new TableServiceClient("");
        public TableClient TC => TSC.GetTableClient("");
    }
}

Csharp相关问答推荐

为什么我不能更改尚未设置的模拟对象属性的值?

Monty Hall游戏节目模拟给我50/50的结果

try 还原包时出错:Dapper已经为System.Data.SQLClient定义了依赖项''''

. NET在上一个操作完成之前,在此上下文实例上启动了第二个操作

注册所有IMediatR类

从.Net 6 DLL注册和检索COM对象(Typelib导出:类型库未注册.(异常来自HRESULT:0x80131165))

C#-VS2022:全局使用和保存时的代码清理

try 在.Net核心身份注册页面中使用AJAX,但没有成功..NET Core 5.0 Razor页面应用程序

Savagger使用Fastendpoint更改用户界面参数

为什么AggregateException的Catch块不足以处理取消?

.NET:从XPath定位原始XML文档中的 node

什么类型的对象存储在大对象堆(LOH)中

在C#中有没有办法减少大型数组中新字符串的分配?

FakeItEasy自动嘲弄内容

C#中COM对象的实际地址

Xamarin Forms应用程序中登录页面的用户名和密码编辑文本之间不需要的空格

C#;AvaloniaUI;MVVM;当另一个窗口上的按钮被单击时,如何更新视图图像源?

如何将行添加到DataGrid以立即显示它?

这是T自身的布尔表达式是什么意思?

无法将';无效';转换为';bool';