Instructing resharper to recognize and validate path arguments
Hi,
I have a feeling that I may be repeating someone here, however I have failed to find any corresponding threads/help topics, so I would appreciate if you'll point me to a corresponding feature help or feature request if there is any.
Is there any way to decorate methods with some metadata to make resharper recognize specific kinds of arguments:
I.e.:
Resharper knows that
WebPageBase.Layout property should contain a valid path to a project file - it validates the path and also brings up a suggestion box with the file browser.
I want to be able to create a custom utility class / MVC html helper that will be able to benefit from the same functionality.
I.e. forward - compatible Scripts class implementation in MVC3:
Scripts.Add("~/Scripts/jquery.js")
For a utility class it is fine to have some tool-specific metadata placed in the code, unless it requires importing of a third-party dll.
So ideally I would like to be able to do something like:
public static class Scripts
{
public static void Add (
// ReSharper type ArgumentType.ProjectFilePath
string url
)
{
///.....
}
}
The same decorations could also be applied to custom MVC Html helpers that could take i.e. Controller names, Action names, html attributes etc.
Best Regards,
Sergii
Please sign in to leave a comment.
On 20.02.2012 15:46, Sergei Sakharov wrote:
>
>
...
Sergei, all that you can achieve already.
Take a look at this article for MVC-specific navigations
http://blogs.jetbrains.com/dotnet/2011/12/providing-intellisense-navigation-and-more-for-custom-helpers-in-aspnet-mvc/
and this one http://devnet.jetbrains.net/thread/293961 for generic paths.
Thanks!
I have been instrumening our helper methods all over the place since you posted your answer (I found format string one expecially benefitial for my current project) and I noticed that we have some third party library dependencies that could also benefit from such instrumentation.
However, for obvious reasons I cannot change these libraries myself. Is there any other way to instrument arguments in this case?
Best Regards,
Sergei
Sergei, annotations for third-party libraries are also possible.
That feature in ReSharper is called "External Annotations". It's xml files similar to XML Doc ones. You can read a little of them, for example, in this artcile http://blogs.jetbrains.com/dotnet/2010/11/resharper-nullreferenceexception-analysis-and-its-contracts/.
Also, you can put that external files not only to ReSharper installation dir, but near to binary assembly with name match assembly and extension ExternalAnnotations.xml and put it in VCS too, so that all your colleagues with ReSharper also will get necessary analyses.