I'm trying to serialize some objects obtained from a 3rd Party .NET Lib to an XML File.
When I Go To Definition
for the object, some of the Properties of that object are marked as [XMLIgnore]
Is there any way to tell my System.Xml.Serialization.XmlSerializer
to ignore the fact that some properties have that attribute and that it should serialize everything in the object.
I could probably obtain the source and recompile it without the XMLIgnore
attributes but it'd be nice if XmlSerializer
had some nice override property like
XmlSerializer xmls = new XmlSerializer(
typeof(MyObject),
Settings.DoNotApplyXMLAttributeRules
);
Thanks in advance
EDIT
Have tried the XmlAttributeOverrides as suggested but not having much joy. Here's the object definition (it's from the FlickrAPI for a Photo)
[Serializable]
public class Photo
{
//Some code omitted
[XmlIgnore]
public string LargeUrl { get; }
}
And heres the serializer code I've written... still doesn't work...
XmlWriter xtw = XmlWriter.Create( Server.MapPath("~/App_Data/Data.xml") );
XmlAttributes photoAttributes = new XmlAttributes();
photoAttributes.XmlIgnore = false;
XmlAttributeOverrides photoOverrides = new XmlAttributeOverrides();
photoOverrides.Add(typeof(Photo), "LargeUrl", photoAttributes);
XmlSerializer xmlphoto = new XmlSerializer(typeof(Photo), photoOverrides);