-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAspectExecutor.cs
More file actions
48 lines (37 loc) · 1.23 KB
/
AspectExecutor.cs
File metadata and controls
48 lines (37 loc) · 1.23 KB
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
using System;
using System.Linq;
namespace BeyondNetCode.Shell.Aop
{
public class AspectExecutor : IAspectExecutor
{
private readonly Type[] _types;
private readonly IPointCut _pointCut;
private readonly Func<Type, IAspect> _aspectFactory;
public AspectExecutor(Type[] types, Func<Type, IAspect> aspectFactory, IPointCut pointCut)
{
_aspectFactory = aspectFactory;
_pointCut = pointCut;
_types = types;
}
public void Execute(IJoinPoint joinPoint)
{
var typesToApply = _types.Where(x => _pointCut.CanApply(joinPoint, x));
if (typesToApply.Any())
{
var aspectsToApply = typesToApply.Select(_aspectFactory).OrderBy(x => x.GetOrder(joinPoint)).ToArray();
var root = aspectsToApply[0];
var aspect = root;
for (var i = 1; i < aspectsToApply.Length; i++)
{
aspect.SetNext(aspectsToApply[i]);
aspect = aspect.GetNext();
}
root.Apply(joinPoint);
}
else
{
joinPoint.Proceed();
}
}
}
}