Back to Devexpress

Create Event Trigger

coderushforroslyn-115513-coding-assistance-code-providers-create-event-trigger.md

latest1.3 KB
Original Source

Create Event Trigger

  • Aug 03, 2020
  • 2 minutes to read

Purpose

This Code Provider creates a method called event trigger , which is used to raise the event. The event trigger creates the event instance, ensures it is not null and raises the event using the parameters passed to the event trigger ( sender and event arguments ).

Availability

Available when the caret is on the event name in its declaration.

Usage

  1. Place the caret on the event name in its declaration.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Create Event Trigger from the menu.

After execution, the Code Provider creates a new method in your class. Use this method to raise the event.

csharp
public class Alarm {
     protected virtual void OnAlarmEvent(object sender, EventArgs e) {
         AlarmEvent?.Invoke(sender, e);
     }
     public event EventHandler AlarmEvent;
    // ...
}
vb
Public Class Alarm
    Protected Overridable Sub OnAlarmEvent(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent AlarmEvent(sender, e)
    End Sub
    Public Event AlarmEvent As EventHandler
    ' ...
End Class