EDIT: The solution to my problem is to implement IXMLSerializer. Thanks everyone for the quick responses.
Hi everyone, I'm having this issue and I do not seem to a find a proper solution to it.
I have the following class
public class Child
{
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
}
[Serializable]
public class Test: ISerializable
{
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private Child _child = new Child();
public Child Child
{
get { return _child; }
set { _child = value; }
}
public Test()
{
}
protected Test(SerializationInfo info, StreamingContext context)
{
if (info.MemberCount > 1)
Child.Id = info.GetInt32("ChildId");
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("ChildId", Child.Id);
}
#endregion
}
If I send the following XML to be deserialzed
<?xml version="1.0" encoding="utf-16"?><Test><Id>0</Id><ChildId>10</ChildId></Test>
using the following code to deserialize
serializer.Deserialize(new StringReader("<?xml version="1.0" encoding="utf-16"?><Test><Id>0</Id><ChildId>10</ChildId></Test>");
I supposed that would call my Serialization constructor, but the thing is that is never getting called.
I am using the above posted XML instead of this one
<?xml version="1.0" encoding="utf-16"?><Test><Id>0</Id><Child><Id>10</Id></Child></Test>
Because I'm getting the xml posted from another application, so I need to manually created child objects and assigned its value manually from within the constructor.
I'll really appreciate all the help and guidance you can provide me.