forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyInitializer.cs
49 lines (41 loc) · 1.52 KB
/
LazyInitializer.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
using System;
using System.Reflection;
using LinFu.DynamicProxy;
using NHibernate.Engine;
using NHibernate.Proxy.Poco;
using NHibernate.Type;
namespace NHibernate.ByteCode.LinFu
{
[Serializable]
public class LazyInitializer : BasicLazyInitializer, global::LinFu.DynamicProxy.IInterceptor
{
private static readonly MethodInfo exceptionInternalPreserveStackTrace =
typeof (Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic);
public LazyInitializer(string entityName, System.Type persistentClass, object id, MethodInfo getIdentifierMethod,
MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType,
ISessionImplementor session)
: base(entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session) {}
#region Implementation of IInterceptor
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)
{
exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] {});
throw ex.InnerException;
}
return returnValue;
}
#endregion
}
}