forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultDynamicLazyFieldInterceptor.cs
64 lines (55 loc) · 1.88 KB
/
DefaultDynamicLazyFieldInterceptor.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
59
60
61
62
63
64
using System;
using System.Reflection;
using NHibernate.Proxy.DynamicProxy;
using NHibernate.Util;
namespace NHibernate.Intercept
{
[Serializable]
// Since v5.2
[Obsolete("Dynamic proxy has been obsoleted, use static proxies instead (see StaticProxyFactory)")]
public class DefaultDynamicLazyFieldInterceptor : IFieldInterceptorAccessor, Proxy.DynamicProxy.IInterceptor
{
public IFieldInterceptor FieldInterceptor { get; set; }
public object Intercept(InvocationInfo info)
{
if (ReflectHelper.IsPropertyGet(info.TargetMethod))
{
if (IsGetFieldInterceptorCall(info.TargetMethod))
{
return FieldInterceptor;
}
if (FieldInterceptor != null)
{
object propValue = info.InvokeMethodOnTarget();
var result = FieldInterceptor.Intercept(info.Target, ReflectHelper.GetPropertyName(info.TargetMethod), propValue);
if (result != AbstractFieldInterceptor.InvokeImplementation)
{
return result;
}
}
}
else if (ReflectHelper.IsPropertySet(info.TargetMethod))
{
if (IsSetFieldInterceptorCall(info.TargetMethod))
{
FieldInterceptor = (IFieldInterceptor) info.Arguments[0];
return null;
}
if (FieldInterceptor != null)
{
FieldInterceptor.MarkDirty();
FieldInterceptor.Intercept(info.Target, ReflectHelper.GetPropertyName(info.TargetMethod), info.Arguments[0], true);
}
}
return info.InvokeMethodOnTarget();
}
private static bool IsGetFieldInterceptorCall(MethodInfo targetMethod)
{
return string.Equals("get_FieldInterceptor", targetMethod.Name, StringComparison.Ordinal) && targetMethod.DeclaringType == typeof(IFieldInterceptorAccessor);
}
private static bool IsSetFieldInterceptorCall(MethodInfo targetMethod)
{
return string.Equals("set_FieldInterceptor", targetMethod.Name, StringComparison.Ordinal) && targetMethod.DeclaringType == typeof(IFieldInterceptorAccessor);
}
}
}