Have you written any unit test code to exercise the function directly (rather than it being invoked indirectly)?
Click "Mark as Answer" on the post that helped you.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
None
0 Points
6 Posts
SerializableDictionary
Mar 03, 2006 07:08 AM|george.polevoy|LINK
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
// DESCRIPTION: Simple workaround for a lack of serialization capability in IDictionary objects
// Before: Dictionary<string, string> d; d["key"] = "value";
// After: SDictionary<string, string> d; d.target["key"] = "value";
// Dictionary is converted to a List of key value paris prior to serialization.
// NOTES: A ~100% memory usage overhead is due to storing the dictionary in a temporary generic collection
namespace Variatron
{
[Serializable]
public class SerializableDictionary<TKey, TValue>
{
[NonSerialized]
public Dictionary<TKey, TValue> target = new Dictionary<TKey, TValue>();
[Serializable]
private class SerializedItem
{
public TKey key;
public TValue value;
}
private List<SerializedItem> data;
public SerializableDictionary()
: base()
{
}
[OnSerializing]
internal void OnSerializing(StreamingContext context)
{
data = new List<SerializedItem>();
foreach (KeyValuePair<TKey, TValue> item in target)
{
SerializedItem si = new SerializedItem();
si.key = item.Key;
si.value = item.Value;
data.Add(si);
}
}
[OnDeserialized]
internal void OnDeserialized(StreamingContext context)
{
target = new Dictionary<TKey, TValue>();
foreach (SerializedItem si in data)
{
target.Add(si.key, si.value);
}
data = null;
}
}
}
None
0 Points
6 Posts
Re: SerializableDictionary
Mar 03, 2006 10:02 AM|george.polevoy|LINK
SDictionary
In my previous post should read:
SerializableDictionary
All-Star
44551 Points
13496 Posts
MVP
Re: SerializableDictionary
Oct 27, 2006 04:48 AM|TATWORTH|LINK
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239