Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name methods that trigger events?

Are there design guidelines on how to name methods that trigger an event in .NET? In different examples I've seen all of:

OnPropertyChanged()
FirePropertyChanged()
TriggerPropertyChanged()
RaisePropertyChanged()

Of course this is not hugely important, but I'd like to do it the "right" way and not confuse others with unusual naming conventions. =)

like image 297
Jens Avatar asked Dec 16 '22 21:12

Jens


2 Answers

You should use OnPropertyChanged according to MSDN, CodeProject and the book Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries (2nd Edition).

EDIT: The quote from CodeProject only refers to the naming of the event, e.g. if your event signalizes that a alarm has happened it should be named AlarmRaised.

Please note that in this article, events are described as "raised" (not "fired" or "triggered"). This convention comes from the team of developers who authored much of the .NET Framework (Cwalina and Abrams, 2006). They prefer the term, "raise," because it doesn't have the negative connotations of the expressions, "fire" or "trigger."

like image 123
RoXX Avatar answered Jan 17 '23 02:01

RoXX


OnPropertyChanged() sounds like the associated event handler.

I'd go with RaisePropertyChanged().

like image 24
Bobby Avatar answered Jan 17 '23 01:01

Bobby