Skip to content

Instantly share code, notes, and snippets.

@alanmcgovern
Created March 22, 2013 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanmcgovern/5220179 to your computer and use it in GitHub Desktop.
Save alanmcgovern/5220179 to your computer and use it in GitHub Desktop.
[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