Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making ReSharper highlight custom HtmlHelper parameters

In the new ReSharper 5.0 there is some MVC specific features for highlighting View and Controllers in views when you type them as strings.

So with ReSharper the string below called "ViewName" will get highlighted and clickable for navigation.

 Html.RenderPartial("ViewName", model); 

My question is if its possible to write custom patterns for custom extension methods. In my case i have a extension method called:

Html.RenderPartialIf(myCondition, "ViewName", model); 

But when I do this ReSharper wont find my view. So can it be done?

Thanks.

like image 394
Magnus Ahlberg Avatar asked Jan 22 '23 01:01

Magnus Ahlberg


1 Answers

Yes, you can do it by using ReSharper's feature called External Annotations.
Add such class to your project:

using System;

namespace JetBrains.Annotations
{
  public class AspMvcViewAttribute : Attribute { }
}

And mark necessary parameters of your methods with this attribute

public static ActionResult RenderPartialIf(this HtmlHelper helper, bool contition, [AspMvcView] string viewName, object model)
{
  ...
}

and all set.

You can look at others ASP.NET MVC attributes in C:\Program Files (x86)\JetBrains\ReSharper\v5.0\Bin\ExternalAnnotations\System.Web.Mvc\System.Web.Mvc.Attributes.xml file.

like image 137
derigel Avatar answered Jan 28 '23 05:01

derigel