I have a general class that implements a dictionary. I created a custom GetEnumerator that iterates over values ββinstead of KeyValuePairs, because I usually don't care about keys. Here is an example:
public class AssetHolder<T> : Dictionary<string, T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged where T : Asset {
I did not add any data to my class (I just added methods), so to make it serializable, I added [DataContract] to the top of the class without any [DataMember] tags. I figured this would just use base class data for serialization / deserialization, but I got the following error:
Cannot pass an object of type "Enumerator [System.String, SignalEngineeringTestPlanner.Asset]" to enter "System.Collections.Generic.IEnumerator`1 [System.Collections.Generic.KeyValuePair`2
I think this means that the DataContractSerializer calls the child enumerator, and it gets confused because it expects a couple, but receives an Asset object. Is there a way that I can (1) tell the DataContractSerializer to use the base class enumerator, or (2) create a special enumeration function and tell the DataContractSerializer to use only the one that is?
source share