Serialize this OBJECT!
-
Hi Can any one provide me with help on how to serialize this collection of objects? I was trying to put some tags, but I am not really getting anywhere.
[XmlRoot ()] public class TableList { private ArrayList tableList; public TableList() { tableList = new ArrayList(); } [XmlArray("tables")] public MyTableItem[] Tables { get { MyTableItem[] tables = new MyTableItem [tableList.Count]; tableList.CopyTo(tables); return tables; } } public int AddTable(MyTableItem table) { return tableList.Add(table); } public class MyTableItem { TableInfo TableInfo = new TableInfo(); [XmlElement("name")] public string TableName = string.Empty; [XmlElement("id")] public string OasisID = string.Empty; [XmlElement("Info")] public Object TableInformation = new Object(); public MyTableItem () { } public MyTableItem (string Name, string OasisID) { this.TableName = Name; this.OasisID = OasisID; TableInformation = TableInfo.GetTableInformation(Name); } } public class TableInfo { public TableInfo () { } public Object GetTableInformation (string tableName) { if (tableName == "Table1") { Table1 tb1 = new Table1(); return tb1; } if (tableName == "Table2") { Table2 tb2 = new Table2(); return tb2; } return null; } } public class Table1 { [XmlAttribute()] public string Prop = "Hello"; public Table1() { } } public class Table2 { [XmlAttribute()] public string WhatIsThis = "Test string"; public Table2() { } }
Thank you very much! -
Hi Can any one provide me with help on how to serialize this collection of objects? I was trying to put some tags, but I am not really getting anywhere.
[XmlRoot ()] public class TableList { private ArrayList tableList; public TableList() { tableList = new ArrayList(); } [XmlArray("tables")] public MyTableItem[] Tables { get { MyTableItem[] tables = new MyTableItem [tableList.Count]; tableList.CopyTo(tables); return tables; } } public int AddTable(MyTableItem table) { return tableList.Add(table); } public class MyTableItem { TableInfo TableInfo = new TableInfo(); [XmlElement("name")] public string TableName = string.Empty; [XmlElement("id")] public string OasisID = string.Empty; [XmlElement("Info")] public Object TableInformation = new Object(); public MyTableItem () { } public MyTableItem (string Name, string OasisID) { this.TableName = Name; this.OasisID = OasisID; TableInformation = TableInfo.GetTableInformation(Name); } } public class TableInfo { public TableInfo () { } public Object GetTableInformation (string tableName) { if (tableName == "Table1") { Table1 tb1 = new Table1(); return tb1; } if (tableName == "Table2") { Table2 tb2 = new Table2(); return tb2; } return null; } } public class Table1 { [XmlAttribute()] public string Prop = "Hello"; public Table1() { } } public class Table2 { [XmlAttribute()] public string WhatIsThis = "Test string"; public Table2() { } }
Thank you very much!