What are the methods that trigger events?

Are there design guidelines, what are the methods that trigger an event in .NET? In different examples, I saw everything:

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

Of course, this is not very important, but I would like to do it in the “right” way and not confuse others with unusual naming conventions. =)

+4
source share
6 answers

You must use OnPropertyChanged in accordance with MSDN , CodeProject, and the Framework Development Guide book : conventions, idioms, and patterns for reusable .NET libraries (2nd edition) .

EDIT: The quote from CodeProject refers only to the name of the event, for example. if your event signals an alarm, it should be called AlarmRaised .

Note that in this article, events are described as being “raised” (not “fired” or “triggered”). This agreement is taken from the development team that created most of the .NET Framework (Cwalina and Abrams, 2006). They prefer the term “raise” because it has no negative connotations of the expressions “fire” or “trigger”.

+5
source

OnPropertyChanged() sounds like a related event handler.

I would go with RaisePropertyChanged() .

+3
source

Why do you need a method to create an event?

If you perform an action from outside the object, then the action that you perform should cause the event to occur without explicitly calling the "event-raise" method.

If your event is created internally, you just need to have a RaiseEvent string, when you want to raise this event, there is no need to call a method for this.

If you have an object that receives a call from another object, just to make it raise an event, I would suggest that you have a problem with your encapsulation ...

EDIT: if you use the method as part of the iNotifyPropertyChanged implementation (and not just to create a PropertyChanged event, which requires all iNotifyPropertyChanged ...), then why not name the "notifyPropertyChanged" method to show that it is part of this implementation?

EDIT2: The MSDN code that follows this convention: How-to. Implementing the INotifyPropertyChanged Interface

+2
source

In order and normal practice, call OnPropertyChanged. It differs in signature from the master event. http://msdn.microsoft.com/en-us/library/ms743695.aspx

+2
source

Other than OnPropertyChanged (), which, at least I find that you are misleading, you can probably use any of the others.

However, which is probably more important, is the consistency of the use of notation throughout the application.

If you choose FirePropertyChanged ", what will be most important in terms of FirePropertyChanged is that the pattern of all quality improvement methods, starting with the prefix" Fire "throughout the application, is respected!

+1
source

I would use FireOnPropertyChanged ().

0
source

All Articles