-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathCustomEventFilter.cs
45 lines (41 loc) · 1.23 KB
/
CustomEventFilter.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
45
namespace Waher.Events.Filter
{
/// <summary>
/// Delegate for custom event filters.
/// </summary>
/// <param name="Event"></param>
/// <returns>If the event is allowed.</returns>
public delegate bool CustomEventFilterDelegate(Event Event);
/// <summary>
/// Implements a custom event filter based on a delegate.
/// </summary>
public class CustomEventFilter : ICustomEventFilter
{
private readonly CustomEventFilterDelegate callback;
/// <summary>
/// Implements a custom event filter based on a delegate.
/// </summary>
/// <param name="Callback">Method called when an event is being evaluated.</param>
public CustomEventFilter(CustomEventFilterDelegate Callback)
{
this.callback = Callback;
}
/// <summary>
/// Converts a delegate to a custom event filter.
/// </summary>
/// <param name="Callback">Callback method.</param>
public static implicit operator CustomEventFilter(CustomEventFilterDelegate Callback)
{
return new CustomEventFilter(Callback);
}
/// <summary>
/// Checks if an event is allowed.
/// </summary>
/// <param name="Event">Event to check.</param>
/// <returns>If event is allowed.</returns>
public bool IsAllowed(Event Event)
{
return this.callback(Event);
}
}
}