Why does "OnFoo" cause an inconsistent naming warning for an event delegate?

I like to prefix event delegates with "On". As an example:

public event FooEvent OnFoo = delegate { };

But resharper with default settings gives me an inconsistent naming warning here, and wants me to remove the "On" and just use "Foo".

Problem is, I don't understand where this error is configured. If I go into C# naming style, I can find the rule settings for Events, and nothing in the configuration suggests "On prefix not allowed", only that it must be UpperCamelCase:

If I add a new rule here, and explicitly give it the "On" name prefix, it will suppress the warning. But still, I do not understand why I see a warning in the first place.

Comment actions Permalink

I'm not sure if there's an option to change that, but using "On" as a prefix for the event name seems like a bad idea.

The convention is that the class will have a protected virtual method called "OnEventName" which raises the event. Your class would need to use "OnOnFoo".

Similarly, for WebForms controls, event handlers are attached using an "OnEventName" attribute on the control. If your class is a WebForms control, you would need to use"OnOnFoo".

The .NET Framework naming guidelines recommend naming your event with "a verb or verb phrase". As far as I can see, no class in the BCL has an event name starting with "On".

Comment actions Permalink

Hello Seth,

Thank you for contacting us. Please accept our apologies for the delay in the reply.

I wasn’t able to reproduce the same naming suggestion on my side. Could you please send us your R# settings - ReSharper | Manage Options | "Export to File" in the context menu for each layer.

Thank you in advance.


Please sign in to leave a comment.