-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractAspect.cs
More file actions
48 lines (37 loc) · 1.18 KB
/
AbstractAspect.cs
File metadata and controls
48 lines (37 loc) · 1.18 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.Collections.Concurrent;
using System.Reflection;
namespace BeyondNetCode.Shell.Aop
{
public abstract class AbstractAspect<T> : IAspect where T : AbstractAspectAttribute
{
private static readonly ConcurrentDictionary<MethodInfo, T> _attributeCache = new ConcurrentDictionary<MethodInfo, T>();
protected T GetAttribute(IJoinPoint joinPoint)
{
return _attributeCache.GetOrAdd(joinPoint.MethodInfo, mi =>
{
var attributes = mi.GetCustomAttributes(typeof(T), true);
return attributes.Length > 0 ? attributes[0] as T : default(T);
});
}
protected virtual void Init(IJoinPoint joinPoint)
{
}
public IAspect GetNext()
{
return _next;
}
public void SetNext(IAspect aspect)
{
_next = aspect;
}
private IAspect _next;
public virtual void Apply(IJoinPoint joinPoint)
{
}
public int GetOrder(IJoinPoint joinPoint)
{
var current = GetAttribute(joinPoint);
return current?.Order ?? int.MaxValue;
}
}
}