开发者

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 belo开发者_StackOverflow中文版w 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜