forked from EddieDemon/BNSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvokeHelper.cs
56 lines (45 loc) · 1.31 KB
/
InvokeHelper.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
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace BNSharp
{
internal delegate void Invokee<T>(Priority p, T args) where T : EventArgs;
internal abstract class InvokeHelperBase
{
private Action<EventArgs> m_freeArgs;
protected InvokeHelperBase(Action<EventArgs> freeArgumentsCallback)
{
m_freeArgs = freeArgumentsCallback;
}
public abstract void Invoke(Priority p);
public abstract void FreeArguments();
protected void FreeArguments(EventArgs args)
{
if (args != null)
{
m_freeArgs(args);
}
}
}
internal sealed class InvokeHelper<T> : InvokeHelperBase where T : EventArgs
{
public InvokeHelper(Invokee<T> target, T arguments, Action<EventArgs> freeArgumentCallback)
: base(freeArgumentCallback)
{
Debug.Assert(target != null);
Target = target;
Arguments = arguments;
}
public Invokee<T> Target;
public T Arguments;
public override void Invoke(Priority p)
{
Target(p, Arguments);
}
public override void FreeArguments()
{
FreeArguments(Arguments);
}
}
}