Tuesday, December 7, 2010

Using IXmlSerializable Interface to serialize Private Members or properties

Suppose let say we have a UDT(User Defined Type) object called person which has the following property's Name,Phone and SSN. Here SSN is read-only properties. When you serializing this person object you get the following error.because XmlSerializer wont serialize the Private members.

image 

To serialize the person object we can implement the  IXmlSerializable Interface as shown below..

image 

Now if you try serialize it will be serialized as XML with out error.

image

Here is the result

image

Nandri(Thanks)

Sreenivasaragavan

No comments: