Do you use a helper extension method to raise events?

Updated by Brook Jeynes [SSW] 1 year ago. See history

123

Enter Intro Text Instead of:

private void RaiseUpdateOnExistingLotReceived() {
if (ExistingLotUpdated != null) {
ExistingLotUpdated();
}
}

...use this event extension method:

public static void Raise<t>(
this EventHandler<t> @event,
object sender,
T args
) where T : EventArgs {
var temp = @event;
if (temp != null) {
temp(sender, args);
}
}
public static void Raise(this Action @event) {
var temp = @event;
if (temp != null) {
temp();
}
}

That means that instead of calling:

RaiseExistingLotUpdated();

...you can do:

ExistingLotUpdated.Raise();

Less code = less code to maintain = less code to be blamed for ;)

acknowledgements
related rules