Hi,
I am writing elements of a particular type into the outgoing xml using IXmlSerializable. I have implemented the schema, and am writing the items out. The code that follows is an example.
public void IXmlSerializable.WriteXml(XmlWriter writer) {
// Write Out Class.
foreach (var item in myItems) {
DataContractSerializer ds = new DataContractSerializer(typeof(MyType));
ds.WriteObject(writer, item);
}
}
The problem I have is that MyType is declared as using references
[DataContract(IsReference = true)]
public class MyType { ...
So when the item has already been written to the xml it needs to be a reference.
How do I know if a reference has already been written to the xml? I am of the opinion that I must just ignore references that I am explicitly not in control of. That way I will make up my own reference id's and reference my own instances.
This is clearly a bad hacked compromise as I am duplicating references that should not be duplicated.
Is there any way to find out what has already been written to see if I can find an id for the item already serialized?
Regards
Craig.