Home > Code Generation, Coding Helpers > Code Providers – Create Event Trigger

Code Providers – Create Event Trigger

February 16th, 2012

The Create Event Trigger CodeRush code provider generates an event trigger for the specified event. An event trigger is a single method that is used to raise an event. Although it is not strictly necessary to create such a trigger, it is useful, as it makes maintenance of the code simpler.

Once the code provider is applied, you can select the target position where the event trigger should be declared. The event trigger will be named OnEventName (where EventName is the name of the original event) and will be ‘virtual’, so derived classes can override the functionality and alter the manner in which events are fired:

CodeRush Create Event Trigger result

Note that the protected OnEventName method allows derived classes to override the event without attaching a delegate to it. A derived class must always call the OnEventName method of the base class to ensure that registered delegates receive the event.

Products: CodeRush Pro
Versions: 11.2 and up
VS IDEs: 2008 and up
Updated: Feb/16/2012
ID: C156

Similar Posts:

  1. Robert Leahey
    February 17th, 2012 at 11:47 | #1

    Hi Alex. This is a provider that I’d really like to use, but I end up avoiding it because I always have to change up the generated implementation code for my standards. Is there any way to make this customizable? Is it template-based, perhaps?

  2. February 17th, 2012 at 12:45 | #2

    @ Robert Leahey
    Unfortunately, it is not customizable. Would you please clarify what standards you mean? Probably, we can change the generated code or make it customizable.