Last active
January 21, 2020 13:44
-
-
Save gsscoder/c287bad9bb98fc950fbf3c4b466c1dbc to your computer and use it in GitHub Desktop.
C# helper class for raising events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
static class EventHelper | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void RaiseEvent(object sender, EventHandler handler, EventArgs args, bool enabled) | |
{ | |
if (enabled && handler != null) { | |
handler(sender, args); | |
} | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void RaiseEvent<T>(object sender, EventHandler<T> handler, Func<T> args, bool enabled) | |
where T : EventArgs | |
{ | |
if (enabled && handler != null) { | |
handler(sender, args()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment