forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyFieldInterceptor.cs
50 lines (46 loc) · 1.19 KB
/
LazyFieldInterceptor.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
using Castle.DynamicProxy;
using NHibernate.Intercept;
using NHibernate.Util;
namespace NHibernate.ByteCode.Castle
{
public class LazyFieldInterceptor : IFieldInterceptorAccessor, global::Castle.DynamicProxy.IInterceptor
{
public IFieldInterceptor FieldInterceptor
{
get;
set;
}
public void Intercept(IInvocation invocation)
{
if (FieldInterceptor != null)
{
if (ReflectHelper.IsPropertyGet(invocation.Method))
{
invocation.Proceed(); // get the existing value
var result = FieldInterceptor.Intercept(
invocation.InvocationTarget,
ReflectHelper.GetPropertyName(invocation.Method),
invocation.ReturnValue);
if (result != AbstractFieldInterceptor.InvokeImplementation)
{
invocation.ReturnValue = result;
}
}
else if (ReflectHelper.IsPropertySet(invocation.Method))
{
FieldInterceptor.MarkDirty();
FieldInterceptor.Intercept(invocation.InvocationTarget, ReflectHelper.GetPropertyName(invocation.Method), null);
invocation.Proceed();
}
else
{
invocation.Proceed();
}
}
else
{
invocation.Proceed();
}
}
}
}