我有一个基本组件,如下所示:

CatalogTableBase.razor.cs(CatalogTableBase.razor的代码后面)

public class CatalogTableBase<T>
    {

        [Parameter]
        public IEnumerable<Feature<T>>? FeatureList { get; set; }

        [Parameter]
        public List<string>? FeatureGroupProperties { get; set; }

        [Parameter]
        public bool ShowHeader { get; set; } = true;

    }

现在,我想创建两个不同的子组件,它们曾经将string实现为一般传递的类型,并且曾经实现为double.

FeatureRangeCatalogTable.razor

@inherits CatalogTableBase<double>

<div>
...
</div>

This throws the CS0115 Error. (FeatureRangeCatalogTable.BuildRenderTree(RenderTreeBuilder): no suitable method found to override)

I guess the thrown error has something to do with the interpreter not knowing what to do with the @inherits-line. I can't wrap around my head why this wouldn't work. Inheriting the class in the code behind (FeatureRangeCatalogTable.razor.cs) also doesn't work.

TL:DR

如何在Blazor组件中实现泛型基类?

推荐答案

CatalogTableBase必须在ComponentBase或类似库之后继承,以使BuildRenderTree可用docs

Csharp相关问答推荐

从Key Vault中提取值以在本地dev web.connect中使用

VS Code - C# - dotnet run找不到文件,但我可以打开并编辑它们吗?

Rx.Net -当关闭序列被触发时如何聚合消息并发出中间输出?

使用GeneratedComInterfaceProperty的.NET 8 COM类对于VB 6/SYS或ALEViewer不可见

Microsoft. SQLServer. Types(106.1000.6)在try 从用户定义的类型检索值时引发异常

如何修改中间件或其注册以正确使用作用域服务?

C#EF Core 8.0表现与预期不符

查找表中的模式

Appsettings.json未加载.Net 8 Blaazor Web程序集

ASP.NET配置kestrel以使用Windows证书存储中的HTTPS

Automapper 12.x将GUID映射到字符串

C#带主体的主构造函数?

如果是,我怎么才能让这个加75,如果不是,我怎么才能减go 100?

使用CollectionView时在.NET Maui中显示数据时出现问题

在';、';附近有错误的语法.必须声明标量变量";@Checkin";.';

匿名类型的AbstractValidator

C# Winforms:从对象树到TreeView的递归转换重复条目

Visual Studio 17.8.0制表符自动完成问题--三缩进

C#USB条形码 scanner 在第二次扫描时未写入行尾字符

为什么C#中的类型别名不能在另一个别名中使用?