ReSharper conventions for names of event handlers
When I add new event handler for any event, VS creates method like object_Click
.
But ReSharper underlines this method as Warning, because all methods should not have any delimeters such as "_".
How can I customize rules of ReSharper so that it doesn't underline such methods? Or may be I should rename such methods?
Thanks in advance.
For C# (or VB), make the following change:
ReSharper | Options | Languages | C# | C# Naming Style, Advanced settings...
Change 'Event subscriptions on fields' from $object$_On$event$
to $object$_$event$
.
You may also want to add additional rules to entity kinds like 'Types and namespaces' to account for code-generated classes such as 'Default'. For example, add a new rule with a '' Name Prefix and a Name Style 'UpperCamelCase'.
Personally, I'd suggest renaming the methods. Generally I think VS comes up with terrible names for both controls and events.
I prefer to make a method name say what it does, not what calls it. That promotes reuse as well. Admittedly the signature of an event handler is often not ideal for reuse - I'd argue that often a lambda expression calling a method with more sensible parameters would be useful:
button.Click += (sender, args) => SaveCurrentDocument();
but obviously the designer doesn't support that :(
Of course, renaming all the methods is going to be more work than just changing the R# settings, if you can find some that work...
I just created an extension for Visual Studio 2010, EventHandler Naming, that lets you specify with a simple pattern what you want your generated eventhandler names to be. The default pattern in the extension is On$(SiteName)$(EventName) which will give you event names like OnBtnNameClick instead of btnName_Click. You can get the extension at http://tech.einaregilsson.com/2010/12/22/better-eventhandler-names-in-visual-studio-2010/