burnt1ce
burnt1ce

Reputation: 14917

.NET: Is There an Interface for Implemented by all XML Serialized objects?

I want a method to return an XML Serialized Typed object. Is there an interface I can use to enforce this requirement?

Upvotes: 0

Views: 97

Answers (4)

John Saunders
John Saunders

Reputation: 161831

There is no interface that means "this object can be XML Serialized". IXmlSerializable means that the caller is stating that it implements XML Serialization on its own, and that the XML Serializer does not need to generate code to serialize it.

The following type is XML Serializable, but does not implement IXmlSerializable:

public class SerializeMe
{
    public string SomeProperty {get; set;}
}

There is no interface that could be used as a return type which could both return an IXmlSerializable instance and the above class.

Upvotes: 0

Chris Ballance
Chris Ballance

Reputation: 34367

Implement ISerializable

Upvotes: 1

moribvndvs
moribvndvs

Reputation: 42497

IXmlSerializable will allow you to customize XML serialization/deserialization. However, it still uses XmlSerializer to serialize data to or from XML.

Upvotes: 1

Related Questions