在Visual Studio中使用自定义方法时,在视图名称上获取红色下划线

ros*_*ead 3 c# asp.net-mvc resharper visual-studio razor

我有很多ASP MVC的扩展方法/辅助类,它们将控制器名称,操作名称或视图名称作为参数(非常类似于默认的HtmlHelper方法).Visual Studio通常使用红色直线强调这些名称,以指示当您使用其中一个内置MVC方法时它们与有效的控制器/操作/视图匹配.有没有办法为我自己的方法获得相同的支持?这是一个不错的小功能,但当我停止使用内置方法时,该功能会慢慢消失.

快速示例:如果已知该视图存在,则在"SomeViewName"字符串下面将有一条红色直线,否则字符串本身将变为红色.

public ActionResult SomeAction()
{
    return View("SomeViewName");
}
Run Code Online (Sandbox Code Playgroud)

这将是我自己的一个方法的示例(它与MVC站点项目本身在一个单独的库中)

// Example action using method
public ActionResult Show(int id) 
{
    return ViewOrNotFound("Show", id);
}

// Example of the method itself
private ActionResult ViewOrNotFound(string viewName, int id) 
{
    var model = DoSomethingToGetModel();
    if (model != null)
    {
        return new ViewResult { ViewName = viewName };
    }
    else 
    {
        return new HttpNotFoundResult();
    }
}
Run Code Online (Sandbox Code Playgroud)

ros*_*ead 5

显然,您需要做的就是使用JetBrains Annotations,因为这是一个ReSharper功能.

public void SomeHelper(this HtmlHelper,[AspMvcController] string controller, [AspMvcAction] string Action, [AspMvcView] string viewName)
{
}
Run Code Online (Sandbox Code Playgroud)