Skip to content

Commit 8e7a3b9

Browse files
committed
NH-3487 - Proposed fix
1 parent d8c15f0 commit 8e7a3b9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/NHibernate/Tuple/EntityModeToTuplizerMapping.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.Serialization;
34
using NHibernate.Util;
45

56
namespace NHibernate.Tuple
67
{
78
/// <summary> Centralizes handling of <see cref="EntityMode"/> to <see cref="ITuplizer"/> mappings. </summary>
89
[Serializable]
9-
public abstract class EntityModeToTuplizerMapping
10+
public abstract class EntityModeToTuplizerMapping : IDeserializationCallback
1011
{
12+
1113
// NH-1660
1214
private readonly IDictionary<EntityMode, ITuplizer> tuplizers
1315
= new LinkedHashMap<EntityMode, ITuplizer>(5, new EntityModeEqualityComparer());
16+
[NonSerialized()]
17+
private bool isFullyDeserialized = false;
18+
19+
public EntityModeToTuplizerMapping()
20+
{
21+
isFullyDeserialized = true;
22+
}
1423

1524
protected internal void AddTuplizer(EntityMode entityMode, ITuplizer tuplizer)
1625
{
26+
EnsureFullyDeserialized();
1727
tuplizers[entityMode] = tuplizer;
1828
}
1929

@@ -22,6 +32,7 @@ protected internal void AddTuplizer(EntityMode entityMode, ITuplizer tuplizer)
2232
/// <returns> The guessed entity mode. </returns>
2333
public virtual EntityMode? GuessEntityMode(object obj)
2434
{
35+
EnsureFullyDeserialized();
2536
foreach (KeyValuePair<EntityMode, ITuplizer> entry in tuplizers)
2637
{
2738
ITuplizer tuplizer = entry.Value;
@@ -41,6 +52,7 @@ protected internal void AddTuplizer(EntityMode entityMode, ITuplizer tuplizer)
4152
/// <returns> The tuplizer, or null if not found. </returns>
4253
public virtual ITuplizer GetTuplizerOrNull(EntityMode entityMode)
4354
{
55+
EnsureFullyDeserialized();
4456
ITuplizer result;
4557
tuplizers.TryGetValue(entityMode, out result);
4658
return result;
@@ -65,5 +77,19 @@ public virtual ITuplizer GetTuplizer(EntityMode entityMode)
6577
}
6678
return tuplizer;
6779
}
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+
}
6894
}
6995
}

src/NHibernate/Util/LinkedHashMap.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.Runtime.Serialization;
56
using System.Text;
67
using NHibernate.DebugHelpers;
78

@@ -18,7 +19,7 @@ namespace NHibernate.Util
1819
/// </remarks>
1920
[DebuggerTypeProxy(typeof(CollectionProxy<>))]
2021
[Serializable]
21-
public class LinkedHashMap<TKey, TValue> : IDictionary<TKey, TValue>
22+
public class LinkedHashMap<TKey, TValue> : IDictionary<TKey, TValue>, IDeserializationCallback
2223
{
2324
[Serializable]
2425
protected class Entry
@@ -359,6 +360,11 @@ private bool RemoveImpl(TKey key)
359360
return result;
360361
}
361362

363+
void IDeserializationCallback.OnDeserialization(object sender)
364+
{
365+
((IDeserializationCallback)entries).OnDeserialization(sender);
366+
}
367+
362368
#region System.Object Members
363369

364370
public override string ToString()

0 commit comments

Comments
 (0)