Skip to content

Commit 38ffcb6

Browse files
committed
Making collection types serializable to make build green
1 parent a72c0b5 commit 38ffcb6

File tree

4 files changed

+208
-64
lines changed

4 files changed

+208
-64
lines changed

Src/NHibernate.Envers.Tests/Integration/Serialization/SerializingCollectionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void VerifyDetached()
4747
// Now serializing and de-serializing the object
4848
rev1 = serializeObject(rev1);
4949

50-
// And checking the colleciton again
50+
// And checking the collection again
5151
CollectionAssert.AreEqual(new[]{ing1}, rev1.Reffering);
5252
}
5353

Src/NHibernate.Envers/Entities/Mapper/Relation/Lazy/Proxy/DictionaryProxy.cs

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,140 @@
55

66
namespace NHibernate.Envers.Entities.Mapper.Relation.Lazy.Proxy
77
{
8+
[Serializable]
89
public class DictionaryProxy<K, V> : IDictionary<K, V>
910
{
10-
private readonly Lazy<IDictionary<K, V>> _delegate;
11+
[NonSerialized]
12+
private readonly IInitializor _initializor;
13+
private IDictionary<K, V> _delegate;
1114

1215
public DictionaryProxy(IInitializor initializor)
1316
{
14-
_delegate = new Lazy<IDictionary<K, V>>(() => (IDictionary<K, V>) initializor.Initialize());
17+
_initializor = initializor;
18+
}
19+
20+
private void checkInit()
21+
{
22+
if (_delegate == null)
23+
{
24+
_delegate = (IDictionary<K, V>) _initializor.Initialize();
25+
}
1526
}
1627

1728
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
1829
{
19-
return _delegate.Value.GetEnumerator();
30+
checkInit();
31+
return _delegate.GetEnumerator();
2032
}
2133

2234
IEnumerator IEnumerable.GetEnumerator()
2335
{
36+
checkInit();
2437
return GetEnumerator();
2538
}
2639

2740
public void Add(KeyValuePair<K, V> item)
2841
{
29-
_delegate.Value.Add(item);
42+
checkInit();
43+
_delegate.Add(item);
3044
}
3145

3246
public void Clear()
3347
{
34-
_delegate.Value.Clear();
48+
checkInit();
49+
_delegate.Clear();
3550
}
3651

3752
public bool Contains(KeyValuePair<K, V> item)
3853
{
39-
return _delegate.Value.Contains(item);
54+
checkInit();
55+
return _delegate.Contains(item);
4056
}
4157

4258
public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex)
4359
{
44-
_delegate.Value.CopyTo(array, arrayIndex);
60+
checkInit();
61+
_delegate.CopyTo(array, arrayIndex);
4562
}
4663

4764
public bool Remove(KeyValuePair<K, V> item)
4865
{
49-
return _delegate.Value.Remove(item);
66+
checkInit();
67+
return _delegate.Remove(item);
5068
}
5169

52-
public int Count => _delegate.Value.Count;
53-
54-
public bool IsReadOnly => _delegate.Value.IsReadOnly;
70+
public int Count
71+
{
72+
get
73+
{
74+
checkInit();
75+
return _delegate.Count;
76+
}
77+
}
5578

56-
public bool ContainsKey(K key)
79+
public bool IsReadOnly
5780
{
58-
return _delegate.Value.ContainsKey(key);
81+
get
82+
{
83+
checkInit();
84+
return _delegate.IsReadOnly;
85+
}
5986
}
6087

6188
public void Add(K key, V value)
6289
{
63-
_delegate.Value.Add(key, value);
90+
checkInit();
91+
_delegate.Add(key, value);
92+
}
93+
94+
public bool ContainsKey(K key)
95+
{
96+
checkInit();
97+
return _delegate.ContainsKey(key);
6498
}
6599

66100
public bool Remove(K key)
67101
{
68-
return _delegate.Value.Remove(key);
102+
checkInit();
103+
return _delegate.Remove(key);
69104
}
70105

71106
public bool TryGetValue(K key, out V value)
72107
{
73-
return _delegate.Value.TryGetValue(key, out value);
108+
checkInit();
109+
return _delegate.TryGetValue(key, out value);
74110
}
75111

76112
public V this[K key]
77113
{
78-
get => _delegate.Value[key];
79-
set => _delegate.Value[key] = value;
114+
get
115+
{
116+
checkInit();
117+
return _delegate[key];
118+
}
119+
set
120+
{
121+
checkInit();
122+
_delegate[key] = value;
123+
}
80124
}
81125

82-
public ICollection<K> Keys => _delegate.Value.Keys;
126+
public ICollection<K> Keys
127+
{
128+
get
129+
{
130+
checkInit();
131+
return _delegate.Keys;
132+
}
133+
}
83134

84-
public ICollection<V> Values => _delegate.Value.Values;
135+
public ICollection<V> Values
136+
{
137+
get
138+
{
139+
checkInit();
140+
return _delegate.Values;
141+
}
142+
}
85143
}
86144
}

Src/NHibernate.Envers/Entities/Mapper/Relation/Lazy/Proxy/ListProxy.cs

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,116 @@
55

66
namespace NHibernate.Envers.Entities.Mapper.Relation.Lazy.Proxy
77
{
8+
[Serializable]
89
public class ListProxy<T> : IList<T>
910
{
10-
private readonly Lazy<IList<T>> _delegate;
11+
[NonSerialized]
12+
private readonly IInitializor _initializor;
13+
private IList<T> _delegate;
1114

1215
public ListProxy(IInitializor initializor)
1316
{
14-
_delegate = new Lazy<IList<T>>(() => (IList<T>) initializor.Initialize());
17+
_initializor = initializor;
18+
}
19+
20+
private void checkInit()
21+
{
22+
if (_delegate == null)
23+
{
24+
_delegate = (IList<T>) _initializor.Initialize();
25+
}
1526
}
1627

1728
public IEnumerator<T> GetEnumerator()
1829
{
19-
return _delegate.Value.GetEnumerator();
30+
checkInit();
31+
return _delegate.GetEnumerator();
2032
}
2133

2234
IEnumerator IEnumerable.GetEnumerator()
2335
{
36+
checkInit();
2437
return GetEnumerator();
2538
}
2639

2740
public void Add(T item)
2841
{
29-
_delegate.Value.Add(item);
42+
checkInit();
43+
_delegate.Add(item);
3044
}
3145

3246
public void Clear()
3347
{
34-
_delegate.Value.Clear();
48+
checkInit();
49+
_delegate.Clear();
3550
}
3651

3752
public bool Contains(T item)
3853
{
39-
return _delegate.Value.Contains(item);
54+
checkInit();
55+
return _delegate.Contains(item);
4056
}
4157

4258
public void CopyTo(T[] array, int arrayIndex)
4359
{
44-
_delegate.Value.CopyTo(array, arrayIndex);
60+
checkInit();
61+
_delegate.CopyTo(array, arrayIndex);
4562
}
4663

4764
public bool Remove(T item)
4865
{
49-
return _delegate.Value.Remove(item);
66+
checkInit();
67+
return _delegate.Remove(item);
5068
}
5169

52-
public int Count => _delegate.Value.Count;
70+
public int Count
71+
{
72+
get
73+
{
74+
checkInit();
75+
return _delegate.Count;
76+
}
77+
}
5378

54-
public bool IsReadOnly => _delegate.Value.IsReadOnly;
79+
public bool IsReadOnly
80+
{
81+
get
82+
{
83+
checkInit();
84+
return _delegate.IsReadOnly;
85+
}
86+
}
5587

5688
public int IndexOf(T item)
5789
{
58-
return _delegate.Value.IndexOf(item);
90+
checkInit();
91+
return _delegate.IndexOf(item);
5992
}
6093

6194
public void Insert(int index, T item)
6295
{
63-
_delegate.Value.Insert(index, item);
96+
checkInit();
97+
_delegate.Insert(index, item);
6498
}
6599

66100
public void RemoveAt(int index)
67101
{
68-
_delegate.Value.RemoveAt(index);
102+
checkInit();
103+
_delegate.RemoveAt(index);
69104
}
70105

71106
public T this[int index]
72107
{
73-
get => _delegate.Value[index];
74-
set => _delegate.Value[index] = value;
108+
get
109+
{
110+
checkInit();
111+
return _delegate[index];
112+
}
113+
set
114+
{
115+
checkInit();
116+
_delegate[index] = value;
117+
}
75118
}
76119
}
77120
}

0 commit comments

Comments
 (0)