-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathDynamicMapInstantiator.cs
76 lines (66 loc) · 1.49 KB
/
DynamicMapInstantiator.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
72
73
74
75
76
using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Mapping;
namespace NHibernate.Tuple
{
//Since v5.2
[Obsolete("This class is not used and will be removed in a future version.")]
[Serializable]
public class DynamicMapInstantiator : IInstantiator
{
public const string KEY = "$type$";
private readonly string entityName;
private readonly HashSet<string> isInstanceEntityNames = new HashSet<string>();
public DynamicMapInstantiator()
{
entityName = null;
}
public DynamicMapInstantiator(PersistentClass mappingInfo)
{
entityName = mappingInfo.EntityName;
isInstanceEntityNames.Add(entityName);
if (mappingInfo.HasSubclasses)
{
foreach (PersistentClass subclassInfo in mappingInfo.SubclassClosureIterator)
isInstanceEntityNames.Add(subclassInfo.EntityName);
}
}
#region IInstantiator Members
public object Instantiate(object id)
{
return Instantiate();
}
public object Instantiate()
{
IDictionary map = GenerateMap();
if (entityName != null)
{
map[KEY] = entityName;
}
return map;
}
protected virtual IDictionary GenerateMap()
{
return new Hashtable();
}
public bool IsInstance(object obj)
{
IDictionary that = obj as IDictionary;
if (that != null)
{
if (entityName == null)
{
return true;
}
string type = (string)that[KEY];
return type == null || isInstanceEntityNames.Contains(type);
}
else
{
return false;
}
}
#endregion
}
}