I have a Config object which I am serializing into XML so I can load it back again later on. In my configuration object I have a dictionary objects
public Dictionary<int, FooConfiguration> Foos
{
get { return foos; }
set
{
if (foos != value)
{
foos = value;
OnPropertyChanged(() => foos);
}
}
}
When I am serializing it doesn't seem to like serializing dictionaries which I can understand, they are complicated objects. So as a workaround I figured I would decorate the property with [XMLIgnore]
and create a list of my objects which would get the values from the dictionary.
public List<FooConfiguration> FooConfigurations
{
get { return Foos.Values.ToList(); }
set
{
int fooNumber = 0;
foreach (var fooConfiguration in value)
{
foos.Add(fooNumber++, fooConfiguration);
}
}
}
This worked as far as serializing goes. I could now see these objects in my XML. The problem is, it was never hitting the setter. Why Would a list be able to serialize but not deserialize?
I have eventually fixed this by using a FooConfiguration[]
instead of a list but this seems a bit weird if you ask me.
As you can see I have a solution, I am just really wanting to understand why its doing what it's doing better.