[Adapdev-commits] Adapdev/src/Adapdev.Data/Schema TableSchemaDictionary.cs,1.1.1.1,1.2
Status: Beta
Brought to you by:
intesar66
From: jhbate <jh...@us...> - 2005-11-06 09:48:33
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30966/src/Adapdev.Data/Schema Modified Files: TableSchemaDictionary.cs Log Message: Changes made for schema xml serialization. Uses the interface IXmlSerializable to support the reading and wrting of the IDictionary type Index: TableSchemaDictionary.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/TableSchemaDictionary.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TableSchemaDictionary.cs 28 Feb 2005 01:31:48 -0000 1.1.1.1 --- TableSchemaDictionary.cs 6 Nov 2005 09:48:24 -0000 1.2 *************** *** 4,11 **** using System.Collections; using System.Text; [Serializable] ! public class TableSchemaDictionary : DictionaryBase { public TableSchema this[String key] { --- 4,16 ---- using System.Collections; using System.Text; + using System.Xml.Serialization; [Serializable] ! public class TableSchemaDictionary : DictionaryBase, IXmlSerializable { + + private const string nameSpace = ""; + private const string tableDictionaryElement = "TableDictionary"; + public TableSchema this[String key] { *************** *** 13,17 **** set { Dictionary[key] = value; } } ! public ICollection Keys { --- 18,22 ---- set { Dictionary[key] = value; } } ! public ICollection Keys { *************** *** 48,52 **** --- 53,121 ---- return sb.ToString(); } + #region IXmlSerializable Members + /// <summary> + /// XmlWriter that is used to write the TableSchemaDictionary as it implements IDictory that is not serializable + /// using the normal methods. This uses the interface IXmlSerializable which isn't offically supported but still + /// exists in the next framework + /// </summary> + /// <param name="writer">System.Xml.XmlWriter</param> + public void WriteXml(System.Xml.XmlWriter writer) + { + XmlSerializer keySer = new XmlSerializer(typeof(String)); + XmlSerializer valueSer = new XmlSerializer(typeof(TableSchema)); + + writer.WriteStartElement(tableDictionaryElement,nameSpace); + foreach(object key in Dictionary.Keys){ + + writer.WriteStartElement("key", nameSpace); + keySer.Serialize(writer,key); + writer.WriteEndElement(); + + writer.WriteStartElement("value", nameSpace); + object value = Dictionary[key]; + valueSer.Serialize(writer, value); + writer.WriteEndElement(); + } + writer.WriteEndElement(); + } + + public System.Xml.Schema.XmlSchema GetSchema() + { + return null; + } + + /// <summary> + /// Custom XmlReader to read the TableSchemaDictionary + /// </summary> + /// <param name="reader">System.Xml.XmlReader</param> + public void ReadXml(System.Xml.XmlReader reader) + { + XmlSerializer keySer = new XmlSerializer(typeof(String)); + XmlSerializer valueSer = new XmlSerializer(typeof(TableSchema)); + + reader.Read(); + reader.ReadStartElement(tableDictionaryElement,nameSpace); + + while(reader.Name != tableDictionaryElement && reader.NodeType != System.Xml.XmlNodeType.EndElement) + { + reader.ReadStartElement("key", nameSpace); + object key = keySer.Deserialize(reader); + reader.ReadEndElement(); + + reader.ReadStartElement("value", nameSpace); + object value = valueSer.Deserialize(reader); + reader.ReadEndElement(); + + Dictionary.Add(key, value); + reader.MoveToContent(); + //navigate past the end element tags to the next table + do{ + reader.Skip(); + }while(reader.NodeType == System.Xml.XmlNodeType.EndElement && reader.Name != tableDictionaryElement); + } + reader.ReadEndElement(); + } + #endregion } } \ No newline at end of file |