继承组件时 Blazor linter 问题

发布于 2025-01-09 01:05:04 字数 423 浏览 2 评论 0原文

我有一个简单的组件叫做 BaseGrid.razor

然后我有另一个名为 CustomGrid.razor

@inherits BaseGrid

...

@{
    base.BuildRenderTree(__builder);
}

...

使用 Rider __builder 时会以红色标记

无法解析符号“__builder”

但项目构建得很好,

在 Visual Studio 中使用 ReSharper 时也会出现此问题,

我不知道这是否是 ReShaper 问题,或者 Visual Studio 也会这样做,但看到所有带红色下划线的文件给了我一个尝试查找文件时遇到真正的问题时感到头痛

i have a simple component called
BaseGrid.razor

and then I have another component called
CustomGrid.razor

@inherits BaseGrid

...

@{
    base.BuildRenderTree(__builder);
}

...

when using Rider __builder gets marked in red saying

cannot resolve symbol '__builder'

but the project builds just fine

this problem also occur when using ReSharper with Visual Studio

i don't know if its a ReShaper problem or Visual Studio does this too but seeing all the files underlined in red is giving me an headache when trying to find with files have a real problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缪败 2025-01-16 01:05:04

在您的情况下,问题是 Razor 编译器设法解释您编码的内容并且偶然工作。在代码视图中,Visual Studio 不知道 __builder 存在:它仅存在于 Razor 编译器从 Razor 文件构建的 C# 类中。

这是我的版本,您向我们展示的内容在语法上“更”正确(不确定这是正确的表达方式,但这是我现在能想到的最好的表达方式)。它不会引发错误,因为 Visual Studio 理解 RenderFragment 的概念。

BaseGrid

<h3>BaseGrid</h3>

@code {
}

网格

我将基本 BuildRenderTree 方法分配给 RenderFragment 委托,然后设置组件来渲染渲染片段。

@inherits BaseGrid
<h3>Grid</h3>

@baseRenderFragment

@code {
    RenderFragment? baseRenderFragment;

    protected override void OnInitialized()
    {
        baseRenderFragment = base.BuildRenderTree;
    }
}

然后看起来像这样:

在此处输入图像描述

In your case the problem is that the Razor compiler manages to interpret what you've coded and by chance work. In the code view Visual Studio has no idea that __builder exists: it only exists in the C# class the Razor compiler builds from the Razor file.

Here's my version of what you've shown us that is "more" syntactically correct (not sure that's the right expression but its the best I can think of now). It doesn't throw errors because Visual Studio understands the concept of a RenderFragment.

BaseGrid

<h3>BaseGrid</h3>

@code {
}

Grid

I assign to base BuildRenderTree method to a RenderFragment delegate and then set the component to render the render fragment.

@inherits BaseGrid
<h3>Grid</h3>

@baseRenderFragment

@code {
    RenderFragment? baseRenderFragment;

    protected override void OnInitialized()
    {
        baseRenderFragment = base.BuildRenderTree;
    }
}

Which then looks like this:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文