[英]Why does Rider think my controller methods are unused?
I'm new to C# and by extension, Rider and this is quite strange to me.我是 C# 的新手,推而广之,Rider,这对我来说很奇怪。
I have a controller with several mappings - only showing the first one, but the problem is the same for all of them.我有一个带有多个映射的 controller - 只显示第一个,但所有映射的问题都是一样的。
The application works fine, each of the individual endpoints does its job as expected when triggered by Postman, but for some reason the method names are greyed out and Rider keeps suggesting removing them because they are "unused".该应用程序运行良好,当 Postman 触发时,每个单独的端点都按预期工作,但由于某种原因,方法名称显示为灰色,Rider 一直建议删除它们,因为它们“未使用”。
{
[ApiController]
[Route("")]
public class HomeController
{
private readonly IToDoService _toDoService;
public HomeController(IToDoService toDoService)
{
_toDoService = toDoService;
}
[HttpGet("")]
[HttpGet("/list")]
public ActionResult<List<ToDo>> ShowTodos()
{
var todos = _toDoService.GetAllToDos();
return todos;
}
Any ideas on how to force Rider to recognize the methods and remove related warnings?关于如何强制 Rider 识别方法并删除相关警告的任何想法? Thanks in advance.提前致谢。
As the other comments already pointed out, this is a limitation of static code analysis.正如其他评论已经指出的那样,这是 static 代码分析的局限性。
But since I personally want to have a Solution free of R# warnings, I explicitly decorate classes like this (eg controllers) with the [UsedImplicitly]
attribute from the JetBrains.Annotations
NuGet package.但是因为我个人想要一个没有 R# 警告的解决方案,所以我使用JetBrains.Annotations
NuGet package 中的[UsedImplicitly]
属性显式修饰类(例如控制器)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.