ReSharper conventions for event handler names

When I add a new event handler for any event, VS creates a method similar to object_Click . But ReSharper emphasizes this method as a Warning, because all methods should not have any delimiters, such as "_".

How to configure ReSharper rules so that they do not emphasize such methods? Or maybe I should rename such methods?

Thanks in advance.

+53
c # resharper
Jun 08
source share
4 answers

Personally, I suggest renaming methods. In general, I think that VS comes up with terrible names for control and events.

I prefer the method name to say what it does, rather than what it calls. It also promotes reuse. Admittedly, an event handler signature is often not ideal for reuse - I would say that often a lambda expression calling a method with more reasonable parameters would be useful:

 button.Click += (sender, args) => SaveCurrentDocument(); 

but obviously the developer does not support this :(

Of course, renaming all the methods will be more work than just changing the settings of R #, if you can find some kind of work ...

+31
Jun 08 2018-10-10T00:
source share

For C # (or VB), make the following change:

ReSharper | Options | Languages ​​| C # | C # name style, Advanced settings ... Change "Subscribing to events in fields" from $object$_On$event$ to $object$_$event$ .

You can also add additional rules to entity types, such as Types and Namespaces, to account for code-generated classes, such as Default. For example, add a new rule with '' Name Prefix and 'UpperCamelCase' name style.

+111
Jul 27 '10 at 15:19
source share

I just created an extension for Visual Studio 2010, EventHandler Naming, which allows you to specify with a simple template what you want your generated event handler names to be. The default extension template is On $ (SiteName) $ (EventName), which will give you event names such as 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/

+6
Dec 23 '10 at 19:37
source share

In the menu of your file you should "Resharper" click it → Options → Naming conventions (in the menu on the left).

From there, you can specify which naming conventions are used for each type and name style.

0
Jun 08 '10 at 5:17
source share



All Articles