-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointCut.cs
More file actions
45 lines (41 loc) · 1.47 KB
/
PointCut.cs
File metadata and controls
45 lines (41 loc) · 1.47 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
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
namespace BeyondNetCode.Shell.Aop
{
public class PointCut : IPointCut
{
private readonly ConcurrentDictionary<(MethodInfo, Type), bool> _cache = new ConcurrentDictionary<(MethodInfo, Type), bool>();
public bool CanApply(IJoinPoint joinPoint, Type aspectType)
{
return _cache.GetOrAdd((joinPoint.MethodInfo, aspectType), key =>
{
var method = key.Item1;
var aspect = key.Item2;
if (aspect.BaseType != null && aspect.BaseType.IsGenericType)
{
var attributeTypes = aspect.BaseType.GetGenericArguments();
if (attributeTypes.Length > 0)
{
var attributeType = attributeTypes.FirstOrDefault(x => typeof(AbstractAspectAttribute).IsAssignableFrom(x));
if (attributeType != null)
{
var attributes = method.GetCustomAttributes(attributeType, true);
return attributes.Length > 0;
}
return false;
}
else
{
return false;
}
}
else
{
return true;
}
});
}
}
}