-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterceptionAttribute.cs
58 lines (50 loc) · 1.33 KB
/
InterceptionAttribute.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
57
58
using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
namespace CastleWithAsyncInterceptors
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class InterceptionAttribute : Attribute
{
protected abstract Type InterceptorType
{
get;
}
public virtual Action<Interceptor> GetInitializer(Type instanceType)
{
return interceptor =>
{
};
}
public Type GetInterceptorType()
{
if (typeof(Interceptor).IsAssignableFrom(InterceptorType))
{
return InterceptorType;
}
throw new ProxyGenerationException($"The type '{InterceptorType}' is not a valid 'IInterceptor'!");
}
protected abstract IEnumerable<object> GetConfigurationComponents();
public override bool Equals(object obj)
{
return this.ComponentEquals(obj, () =>
{
var vo = obj as InterceptionAttribute;
return GetConfigurationComponents().SequenceEqual(vo.GetConfigurationComponents());
});
}
public override int GetHashCode()
{
return this.CombineHashCodes(GetConfigurationComponents());
}
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class IgnoreInterceptionAttribute : Attribute
{
public abstract Type InterceptionAttributeType
{
get;
}
}
}