IXmlSerializable and XmlRootAttribute

Cluddyelalo

New Member
I have a weird requirement on xml serialization.Refer the following C# code (which cannot be compiled due to the variable 'rootName' is out of scope). My intention is to make my class GeneralData be 'general'. Which means this class can be serialized to different XML strings with different root element according to the input parameter for the class constructor.\[code\][XmlRoot(ElementName = rootName)]public class GeneralData : Dictionary<String, Object>, IXmlSerializable{ public string rootName; public GeneralData(string rootName) { this.rootName = rootName; } public System.Xml.Schema.XmlSchema GetSchema() { throw new NotImplementedException(); } public void ReadXml(System.Xml.XmlReader reader) { throw new NotImplementedException(); } public void WriteXml(System.Xml.XmlWriter writer) { foreach (var key in Keys) { var value = http://stackoverflow.com/questions/12779940/base[key]; writer.WriteElementString(key, value.ToString()); } }}\[/code\]Anyone can help me to accomplish the task? Maybe in a totally different way?Thanks in advance!!
 
Back
Top