Fragilerus
Fragilerus

Reputation: 1899

IXMLSerializeable

I need to implement IXMLSerializeable for custom serialization on 2 members, but I want the rest of the members to be serialized with the default serialization. Or at least, is there a way for me to invoke the standard serialization on the other members? The types of the other members are very large and deeply neseted classes, and it would not be practicle to define the serialization of every member all the way down the chain.

Upvotes: 1

Views: 121

Answers (1)

Johannes
Johannes

Reputation: 11

you can use the XmlSerializer to serialize your members via the standard way:

    public voind WriteXml SerializeObjectToXml(XmlWriter writer)
    {

        ...

        XmlSerializer xmlSer;
        xmlSer = new XmlSerializer(<yourMember>.GetType());
        xmlSer.Serialize(strWriter, source);

        ...
    }

    public void ReadXml(XmlReader reader)
    {

        ...

        XmlSerializer xmlSer = new XmlSerializer(<yourMemberType>);
        <yourMemberType> deserializationResult = (<yourMemberType>)xmlSer.Deserialize(reader);

        ...                        
    }

Hope that helps,

Johannes

Upvotes: 1

Related Questions