Do you use a helper extension method to raise events?

Updated by Brook Jeynes [SSW] 2 years ago. See history

123
No component provided for introEmbed

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

Adam Cogan
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star