forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventHelpers.cs
44 lines (41 loc) · 1.8 KB
/
EventHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
namespace Microsoft.Xna.Framework
{
/// <summary>
/// Provides helper methods to make it easier
/// to safely raise events.
/// </summary>
internal static class EventHelpers
{
/// <summary>
/// Safely raises an event by storing a copy of the event's delegate
/// in the <paramref name="handler"/> parameter and checking it for
/// null before invoking it.
/// </summary>
/// <typeparam name="TEventArgs"></typeparam>
/// <param name="sender">The object raising the event.</param>
/// <param name="handler"><see cref="EventHandler{TEventArgs}"/> to be invoked</param>
/// <param name="e">The <typeparamref name="TEventArgs"/> passed to <see cref="EventHandler{TEventArgs}"/></param>
internal static void Raise<TEventArgs>(object sender, EventHandler<TEventArgs> handler, TEventArgs e)
{
if (handler != null)
handler(sender, e);
}
/// <summary>
/// Safely raises an event by storing a copy of the event's delegate
/// in the <paramref name="handler"/> parameter and checking it for
/// null before invoking it.
/// </summary>
/// <param name="sender">The object raising the event.</param>
/// <param name="handler"><see cref="EventHandler"/> to be invoked</param>
/// <param name="e">The <see cref="EventArgs"/> passed to <see cref="EventHandler"/></param>
internal static void Raise(object sender, EventHandler handler, EventArgs e)
{
if (handler != null)
handler(sender, e);
}
}
}