Keep in mind that in classes that are serializable, SerializableAttribute is labeled as opposed to an interface implementation. From MSDN :
Any class that can be serialized must be marked SerializableAttribute. If a class needs to control its serialization process, it can implement the ISerializable interface.
What you need to do is make your own class that implements the IDictioanry interface, and every time someone calls, use a reflex to check if the passed item has a serializable attribute (and throws an exception if it fails).
The code would look like
class MyDictionary<TKey, TValue> : IDictionary<TKey, TValue> { private Dictionary<TKey, TValue> d; public void Add(TKey key, TValue value) { if( value.GetType().IsSerializable ) { d.Add(key, value); } else { throw new ArgumentException(); } } ..... }
source share