H
Hoss
Quick Remark.
I have a class that looks like this
[Serializable]
[XmlRoot("Class")]
public Class
{
[XmlAttribute]
public int Attribu
{
get{};set{};
}
[XmlAttribute]
public int Attribu
{
get{};set{};
}
}
Set up perfectly for Xml Serialization / Deserialization. One of the
great things about this is that if I, say, add a column to the
database, all I need to do is create the new public property on my
class. I do not have to say add a few lines to my SerializeToXml()
method, or add code to my DeserializeFromXml() method, since the
System.Xml.Serialization.XmlSerializer determines all that information
dynamically using Reflection. Okay, great, we have realized the
flexibility benefits from that.
But how do I set up my Deserialization constructor to work with that?
Consider:
public Class(string id)
{
string xml = FetchXml() // Get Xml representing this object
from somewhere. The ID is the key on the data.
Class instance = XmlSerializer.Deserialize(xml);
this.Attrib = instance.Attrib;
this.Attrib = instance.Attrib;
this.Attrib = instance.Attrib;
... ect.
}
You cant say
this = XmlSerializer.Deserialize(xml);
So - is there any way to Deserialize from xml and populate all the
properties in a CONSTRUCTOR without enumerating each property ?? I
guess I could use a static factory instead of a constructor.
Thoughts?
I have a class that looks like this
[Serializable]
[XmlRoot("Class")]
public Class
{
[XmlAttribute]
public int Attribu
{
get{};set{};
}
[XmlAttribute]
public int Attribu
{
get{};set{};
}
}
Set up perfectly for Xml Serialization / Deserialization. One of the
great things about this is that if I, say, add a column to the
database, all I need to do is create the new public property on my
class. I do not have to say add a few lines to my SerializeToXml()
method, or add code to my DeserializeFromXml() method, since the
System.Xml.Serialization.XmlSerializer determines all that information
dynamically using Reflection. Okay, great, we have realized the
flexibility benefits from that.
But how do I set up my Deserialization constructor to work with that?
Consider:
public Class(string id)
{
string xml = FetchXml() // Get Xml representing this object
from somewhere. The ID is the key on the data.
Class instance = XmlSerializer.Deserialize(xml);
this.Attrib = instance.Attrib;
this.Attrib = instance.Attrib;
this.Attrib = instance.Attrib;
... ect.
}
You cant say
this = XmlSerializer.Deserialize(xml);
So - is there any way to Deserialize from xml and populate all the
properties in a CONSTRUCTOR without enumerating each property ?? I
guess I could use a static factory instead of a constructor.
Thoughts?