coderushforroslyn-115513-coding-assistance-code-providers-create-event-trigger.md
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 ).
Available when the caret is on the event name in its declaration.
Place the caret on the event name in its declaration.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
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.
public class Alarm {
protected virtual void OnAlarmEvent(object sender, EventArgs e) {
AlarmEvent?.Invoke(sender, e);
}
public event EventHandler AlarmEvent;
// ...
}
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