views:

95

answers:

1

Hello,

On one side, in Vb.Net when you add an event handler to an object the created method is named: <NameOfTheObject>_<NameOfTheMethod>.

As I like to have consistent syntax I always follow this rule when creating event handlers by hand.

On the other side when I create private variables I prefix them with m_ as this is a common thing used by the community, in C# people use to put _ at the beginning of a variable but this is no CLS compliant.

At the end, when I create event handlers for events raised by private variables I end with Subs like m_myVariable_MyEvent. Code Analysis (Fx Cop) is complainig about this way of naming because the method does not start with uppercase and because the _, so the question is:

What naming standards do you follow when creating event handlers by hand that follow the Fxcop rules if any?

Thanks in advance.

A: 

I always use __xxx_eventName for controls and _xxx_eventName for private variables that I want to catch events. (I always set controls as private.) This places the handlers at the beginning of lists and immediately after the variable. Quite useful with maintainence, troubleshooting, and debugging. If a handler is used my multiple events then I generally use descriptiveName_eventNameHandler.

For non-private, I always use "Design Guidelines for Developing Class Libraries" and "Framework Design Guidelines...". (I have the framework book on my desk.)

You can add a GlobalSuppressions.vb file to the root folder of the project and exclude specific rules. For instance, I usually have to do this because I use my last name in namespaces, too few objects in namespaces, and catching general exceptions.

AMissico