|
2 | 2 | using System.Collections;
|
3 | 3 | using System.Collections.Generic;
|
4 | 4 | using System.Dynamic;
|
| 5 | +using System.Runtime.Serialization; |
5 | 6 |
|
6 | 7 | namespace NHibernate.Util
|
7 | 8 | {
|
8 | 9 | [Serializable]
|
9 |
| - public class DynamicDictionaryWrapper : DynamicObject, IDictionary, IDictionary<string, object> |
| 10 | + public sealed class DynamicDictionaryWrapper : DynamicObject, |
| 11 | + IDictionary, |
| 12 | + IDictionary<string, object>, |
| 13 | + ISerializable, |
| 14 | + IDeserializationCallback |
10 | 15 | {
|
11 | 16 | private readonly Dictionary<string, object> _data = new Dictionary<string, object>();
|
12 | 17 |
|
| 18 | + public DynamicDictionaryWrapper() |
| 19 | + { |
| 20 | + } |
| 21 | + |
| 22 | + private DynamicDictionaryWrapper(SerializationInfo info, StreamingContext context) |
| 23 | + { |
| 24 | + _data = info.GetValue<Dictionary<string, object>>("Data"); |
| 25 | + } |
| 26 | + |
13 | 27 | public override bool TryGetMember(GetMemberBinder binder, out object result)
|
14 | 28 | {
|
15 | 29 | return _data.TryGetValue(binder.Name, out result);
|
@@ -187,5 +201,15 @@ object IDictionary<string, object>.this[string key]
|
187 | 201 | ICollection<object> IDictionary<string, object>.Values => ((IDictionary<string, object>) _data).Values;
|
188 | 202 |
|
189 | 203 | ICollection<string> IDictionary<string, object>.Keys => ((IDictionary<string, object>) _data).Keys;
|
| 204 | + |
| 205 | + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) |
| 206 | + { |
| 207 | + info.AddValue("Data", _data); |
| 208 | + } |
| 209 | + |
| 210 | + void IDeserializationCallback.OnDeserialization(object sender) |
| 211 | + { |
| 212 | + _data.OnDeserialization(sender); |
| 213 | + } |
190 | 214 | }
|
191 | 215 | }
|
0 commit comments