继承组件时 Blazor linter 问题
我有一个简单的组件叫做 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的情况下,问题是 Razor 编译器设法解释您编码的内容并且偶然工作。在代码视图中,Visual Studio 不知道 __builder 存在:它仅存在于 Razor 编译器从 Razor 文件构建的 C# 类中。
这是我的版本,您向我们展示的内容在语法上“更”正确(不确定这是正确的表达方式,但这是我现在能想到的最好的表达方式)。它不会引发错误,因为 Visual Studio 理解 RenderFragment 的概念。
BaseGrid
网格
我将基本
BuildRenderTree
方法分配给RenderFragment
委托,然后设置组件来渲染渲染片段。然后看起来像这样:
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
Grid
I assign to base
BuildRenderTree
method to aRenderFragment
delegate and then set the component to render the render fragment.Which then looks like this: