views:

35

answers:

1

I want to ignore all elements of Dictionary while serializing as those members cause an exception

example class:

public class TestClass{
    public string StringTest { get; set; }
    public int IntTest { get; set; }
    public Dictionary<int, string> someDictionary { get; set; }
}

What i tried(unsuccessfull)

XmlAttributeOverrides xOver = new XmlAttributeOverrides();

XmlAttributes attrs = new XmlAttributes();
attrs.XmlIgnore = true;

xOver.Add(typeof(Dictionary<int, string>), attrs);

XmlSerializer serialiser = new XmlSerializer(objectToConvert.GetType(), xOver);
serialiser.Serialize(writer, objectToConvert);
A: 

Have you tried it like this instead.

[XmlIgnore]
public Dictionary<int.string> someDictionary{get;set;}
ywm
that would work indeed but i want to do it dynamically.
MichaelD