Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper conventions for names of event handlers

Tags:

c#

resharper

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.

like image 458
Pavel Belousov Avatar asked Jun 08 '10 04:06

Pavel Belousov


People also ask

How do you name an event handler?

Event handlers must have a name with the suffix EventHandler. The following example illustrates names that consist of the delegate name and the EventHandler suffix. Event handler naming conventions apply to pre and post event handlers.

What method is used to register and event handler?

To register a handler, use the addEventHandler() method. This method takes the event type and the handler as arguments.

What is event and EventHandler?

In programming, an event handler is a callback routine that operates asynchronously once an event takes place. It dictates the action that follows the event. The programmer writes a code for this action to take place. An event is an action that takes place when a user interacts with a program.


1 Answers

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'.

like image 65
David North Avatar answered Sep 17 '22 13:09

David North