部分类中继承 ComponentBase 的继承基类给出错误

Pow*_*000 3 c# partial-classes blazor blazor-server-side

我正在使用 Something.razor 文件和 Something.razor.cs 文件背后的代码。我的分部类继承自 SomethingBase,而 SomethingBase 本身又继承自 ComponentBase。

然而这会产生错误

CS0115 .buildrendertree(rendertreebuilder)':没有找到合适的方法来覆盖部分类 CS0263 的部分声明,不得指定不同的基类。

但是,如果 Something 直接继承自 ComponentBase 则没有问题。

第一个问题请温柔一点。如果需要的话,我会在早上更新代码和更多细节。

Hen*_*man 7

使用代码隐藏文件,您有两个位置可以指定基类。

始终必须在 .razor 文件中指定它,因为您不希望在那里使用默认值:

// Something.razor
@inherits SomethingBase 
Run Code Online (Sandbox Code Playgroud)

然后您可以在 .razor.cs 文件中进行选择:

// Something.razor.cs (a)
partial class Something      // take base class from other part
{
} 
Run Code Online (Sandbox Code Playgroud)

或者

// Something.razor.cs (b)
public partial class Something : SomethingBase  // must use the same as other part
{
} 
Run Code Online (Sandbox Code Playgroud)

我会使用 (a) 。