forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProxyHelper.cs
71 lines (60 loc) · 1.57 KB
/
ProxyHelper.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
65
66
67
68
69
70
71
using System;
using NHibernate.Proxy.DynamicProxy;
namespace NHibernate.Test.DynamicEntity
{
[Obsolete("Require dynamic proxies")]
public class ProxyHelper
{
private static readonly ProxyFactory proxyGenerator = new ProxyFactory();
private static T NewProxy<T>(object id)
{
return (T)proxyGenerator.CreateProxy(typeof(T), new DataProxyHandler(typeof (T).FullName, id),
new[] {typeof (IProxyMarker), typeof (T)});
}
public static Person NewPersonProxy()
{
return NewProxy<Person>(0L);
}
public static Person NewPersonProxy(object id)
{
return NewProxy<Person>(id);
}
public static Customer NewCustomerProxy()
{
return NewProxy<Customer>(0L);
}
public static Customer NewCustomerProxy(object id)
{
return NewProxy<Customer>(id);
}
public static Company NewCompanyProxy()
{
return NewProxy<Company>(0L);
}
public static Company NewCompanyProxy(object id)
{
return NewProxy<Company>(id);
}
public static Address NewAddressProxy()
{
return NewProxy<Address>(0L);
}
public static Address NewAddressProxy(object id)
{
return NewProxy<Address>(id);
}
public static string ExtractEntityName(object obj)
{
// Our custom Proxy instances actually bundle
// their appropriate entity name, so we simply extract it from there
// if this represents one of our proxies; otherwise, we return null
IProxyMarker pm = obj as IProxyMarker;
if (pm != null)
{
DataProxyHandler myHandler = pm.DataHandler;
return myHandler.EntityName;
}
return null;
}
}
}