forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultLazyInitializer.cs
44 lines (39 loc) · 1.33 KB
/
DefaultLazyInitializer.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
using System;
using System.Reflection;
using NHibernate.Engine;
using NHibernate.Proxy.DynamicProxy;
using NHibernate.Proxy.Poco;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate.Proxy
{
[Serializable]
// Since v5.2
[Obsolete("Dynamic proxy has been obsoleted, use static proxies instead (see StaticProxyFactory)")]
public class DefaultLazyInitializer : BasicLazyInitializer, DynamicProxy.IInterceptor
{
public DefaultLazyInitializer(string entityName, System.Type persistentClass, object id, MethodInfo getIdentifierMethod,
MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType,
ISessionImplementor session, bool overridesEquals)
: base(entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session, overridesEquals) {}
public object Intercept(InvocationInfo info)
{
object returnValue;
try
{
returnValue = base.Invoke(info.TargetMethod, info.Arguments, info.Target);
// Avoid invoking the actual implementation, if possible
if (returnValue != InvokeImplementation)
{
return returnValue;
}
returnValue = info.TargetMethod.Invoke(GetImplementation(), info.Arguments);
}
catch (TargetInvocationException ex)
{
throw ReflectHelper.UnwrapTargetInvocationException(ex);
}
return returnValue;
}
}
}