1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Runtime . Serialization ;
3
4
using NHibernate . Util ;
4
5
5
6
namespace NHibernate . Tuple
6
7
{
7
8
/// <summary> Centralizes handling of <see cref="EntityMode"/> to <see cref="ITuplizer"/> mappings. </summary>
8
9
[ Serializable ]
9
- public abstract class EntityModeToTuplizerMapping
10
+ public abstract class EntityModeToTuplizerMapping : IDeserializationCallback
10
11
{
12
+
11
13
// NH-1660
12
14
private readonly IDictionary < EntityMode , ITuplizer > tuplizers
13
15
= new LinkedHashMap < EntityMode , ITuplizer > ( 5 , new EntityModeEqualityComparer ( ) ) ;
16
+ [ NonSerialized ( ) ]
17
+ private bool isFullyDeserialized = false ;
18
+
19
+ public EntityModeToTuplizerMapping ( )
20
+ {
21
+ isFullyDeserialized = true ;
22
+ }
14
23
15
24
protected internal void AddTuplizer ( EntityMode entityMode , ITuplizer tuplizer )
16
25
{
26
+ EnsureFullyDeserialized ( ) ;
17
27
tuplizers [ entityMode ] = tuplizer ;
18
28
}
19
29
@@ -22,6 +32,7 @@ protected internal void AddTuplizer(EntityMode entityMode, ITuplizer tuplizer)
22
32
/// <returns> The guessed entity mode. </returns>
23
33
public virtual EntityMode ? GuessEntityMode ( object obj )
24
34
{
35
+ EnsureFullyDeserialized ( ) ;
25
36
foreach ( KeyValuePair < EntityMode , ITuplizer > entry in tuplizers )
26
37
{
27
38
ITuplizer tuplizer = entry . Value ;
@@ -41,6 +52,7 @@ protected internal void AddTuplizer(EntityMode entityMode, ITuplizer tuplizer)
41
52
/// <returns> The tuplizer, or null if not found. </returns>
42
53
public virtual ITuplizer GetTuplizerOrNull ( EntityMode entityMode )
43
54
{
55
+ EnsureFullyDeserialized ( ) ;
44
56
ITuplizer result ;
45
57
tuplizers . TryGetValue ( entityMode , out result ) ;
46
58
return result ;
@@ -65,5 +77,19 @@ public virtual ITuplizer GetTuplizer(EntityMode entityMode)
65
77
}
66
78
return tuplizer ;
67
79
}
80
+
81
+ private void EnsureFullyDeserialized ( )
82
+ {
83
+ if ( ! isFullyDeserialized )
84
+ {
85
+ ( ( IDeserializationCallback ) this ) . OnDeserialization ( this ) ;
86
+ }
87
+ }
88
+
89
+ void IDeserializationCallback . OnDeserialization ( object sender )
90
+ {
91
+ ( ( IDeserializationCallback ) tuplizers ) . OnDeserialization ( sender ) ;
92
+ isFullyDeserialized = true ;
93
+ }
68
94
}
69
95
}
0 commit comments