forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyEntityInstantiator.cs
57 lines (52 loc) · 1.16 KB
/
MyEntityInstantiator.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
using System;
using NHibernate.Tuple;
namespace NHibernate.Test.DynamicEntity.Tuplizer
{
[Obsolete("Require dynamic proxies")]
public class MyEntityInstantiator : IInstantiator
{
private readonly System.Type entityType;
public MyEntityInstantiator(System.Type entityType)
{
this.entityType = entityType;
}
public object Instantiate(object id)
{
if (typeof(Person).Equals(entityType))
{
return ProxyHelper.NewPersonProxy(id);
}
if (typeof(Customer).Equals(entityType))
{
return ProxyHelper.NewCustomerProxy(id);
}
else if (typeof(Company).Equals(entityType))
{
return ProxyHelper.NewCompanyProxy(id);
}
else if (typeof(Address).Equals(entityType))
{
return ProxyHelper.NewAddressProxy(id);
}
else
{
throw new ArgumentException("unknown entity for instantiation [" + entityType.FullName + "]");
}
}
public object Instantiate()
{
return Instantiate(null);
}
public bool IsInstance(object obj)
{
try
{
return entityType.IsInstanceOfType(obj);
}
catch (Exception e)
{
throw new HibernateException("could not get handle to entity-name as interface : " + e);
}
}
}
}