Created
March 22, 2013 09:53
-
-
Save alanmcgovern/5220179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Serializable] | |
public class SerializableDictionary<K, V> : Dictionary<K, V> | |
{ | |
public SerializableDictionary () | |
{ | |
} | |
public SerializableDictionary (IEqualityComparer<K> comparer) | |
: base (comparer) | |
{ | |
} | |
protected SerializableDictionary (SerializationInfo info, | |
StreamingContext context) | |
{ | |
foreach (var v in (KeyValuePair<K, V>[]) info.GetValue ("contents", typeof (KeyValuePair<K, V>[]))) | |
Add (v.Key, v.Value); | |
} | |
public override void GetObjectData (SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue ("contents", this.ToArray ()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment