[Adapdev-commits] Adapdev/src/Adapdev.Data/Schema ColumnSchemaDictionary.cs,1.1.1.1,1.2
Status: Beta
Brought to you by:
intesar66
From: jhbate <jh...@us...> - 2005-11-06 09:46:57
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30632/src/Adapdev.Data/Schema Modified Files: ColumnSchemaDictionary.cs Log Message: Changes made for schema xml serialization. Uses the interface IXmlSerializable to support the reading and wrting of the IDictionary type Index: ColumnSchemaDictionary.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/ColumnSchemaDictionary.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ColumnSchemaDictionary.cs 28 Feb 2005 01:31:47 -0000 1.1.1.1 --- ColumnSchemaDictionary.cs 6 Nov 2005 09:46:49 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- using System.Collections; using System.Text; + using System.Xml.Serialization; /// <summary> *************** *** 10,15 **** /// [Serializable] ! public class ColumnSchemaDictionary : DictionaryBase { public ColumnSchema this[String key] { --- 11,19 ---- /// [Serializable] ! public class ColumnSchemaDictionary : DictionaryBase, IXmlSerializable { + private const string nameSpace = ""; + private const string columnDictionaryElement = "ColumnDictionary"; + public ColumnSchema this[String key] { *************** *** 52,57 **** --- 56,120 ---- return sb.ToString(); } + #region IXmlSerializable Members + /// <summary> + /// XmlWriter that is used to write the ColumnSchemaDictionary 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(ColumnSchema)); + + writer.WriteStartElement(columnDictionaryElement, 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 ColumnSchemaDictionary + /// </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(ColumnSchema)); + + reader.Read(); + reader.ReadStartElement(columnDictionaryElement, nameSpace); + + while(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(); + } + reader.ReadEndElement(); + } + #endregion } } \ No newline at end of file |