Ejemplo n.º 1
0
        public void ReadXml(System.Xml.XmlReader r)
        {
            int depth = r.Depth;

            r.ReadStartElement();
            bool hasRead = false;

            while (r.Depth > depth)
            {
                if (r.IsStartElement())
                {
                    XmlSerializer ser = XmlTypeAssociator <T> .GetSerializer(r);

                    XMLSerializeManager.Report("Deserializing: " + r.Name);
                    Add((T)ser.Deserialize(r));
                    r.MoveToContent();
                }
                else
                {
                    r.Read();
                }
                hasRead = true;
            }
            if (hasRead)
            {
                r.ReadEndElement();
            }
        }
Ejemplo n.º 2
0
        public void ReadXml(XmlReader r)
        {
            r.ReadStartElement();
            Id = r.GetAttribute("id");
            r.ReadStartElement("items");
            if (r.NodeType == System.Xml.XmlNodeType.EndElement)
            {
                r.ReadEndElement();//--items
                return;
            }
            while (r.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                XMLSerializeManager.Report("Deserializing: " + r.Name);
                XmlSerializer valueSer = XmlTypeAssociator <T> .GetSerializer(r);

                object obj   = valueSer.Deserialize(r);
                T      value = (T)obj;
                if (value.Id != null)
                {
                    this[value.Id] = value;
                }
            }
            r.ReadEndElement();//--items
            r.ReadEndElement();
        }
Ejemplo n.º 3
0
        public void WriteXml(System.Xml.XmlWriter w)
        {
            w.WriteStartElement("dictionary");
            foreach (TKey key in Keys)
            {
                w.WriteStartElement("item");

                w.WriteStartElement("key");
                XmlSerializer keySer = XmlTypeAssociator <TKey> .GetSerializer(key.GetType());

                XMLSerializeManager.Report("Serializing key: " + key.GetType().Name);
                keySer.Serialize(w, key);
                w.WriteEndElement();

                w.WriteStartElement("value");
                TValue        value    = this[key];
                XmlSerializer valueSer = XmlTypeAssociator <TValue> .GetSerializer(value.GetType());

                XMLSerializeManager.Report("Serializing value: " + value.GetType().Name);
                valueSer.Serialize(w, value);
                w.WriteEndElement();

                w.WriteEndElement();
            }
            w.WriteEndElement();
        }
Ejemplo n.º 4
0
        public void WriteXml(System.Xml.XmlWriter w)
        {
            if (m_Value == null)
            {
                return;
            }
            XmlSerializer ser = XmlTypeAssociator <T> .GetSerializer(m_Value.GetType());

            XMLSerializeManager.Report("Serializing value: " + m_Value.GetType().Name);
            ser.Serialize(w, m_Value);
        }
Ejemplo n.º 5
0
        public void WriteXml(System.Xml.XmlWriter w)
        {
            foreach (T item in this)
            {
                XmlSerializer ser = XmlTypeAssociator <T> .GetSerializer(item.GetType());

                XMLSerializeManager.Report("Serializing item: " + item.GetType().Name);
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("", "");
                ser.Serialize(w, item, ns);
            }
        }
Ejemplo n.º 6
0
        public void ReadXml(System.Xml.XmlReader r)
        {
            if (r.IsEmptyElement)
            {
                return;
            }
            r.ReadStartElement();
            XmlSerializer ser = XmlTypeAssociator <T> .GetSerializer(r.Name);

            XMLSerializeManager.Report("Deserializing: " + r.Name);
            m_Value = (T)ser.Deserialize(r);
            r.MoveToContent();
            r.ReadEndElement();
        }
Ejemplo n.º 7
0
        public void WriteXml(XmlWriter w)
        {
            if (Id != null)
            {
                w.WriteAttributeString("id", Id);
            }
            w.WriteStartElement("items");
            foreach (IIdItem value in Values)
            {
                XMLSerializeManager.Report("Serializing: " + value.GetType().Name);
                XmlSerializer valueSer = XmlTypeAssociator <T> .GetSerializer(value.GetType());

                valueSer.Serialize(w, value, new XmlSerializerNamespaces());
            }
            w.WriteEndElement();
        }
Ejemplo n.º 8
0
        public void ReadXml(System.Xml.XmlReader r)
        {
            r.ReadStartElement();
            bool hasRead = false;

            r.ReadStartElement("dictionary");
            int begin_d = r.Depth;

            while (readStartElementOK("item", r))
            {
                r.ReadStartElement("key");
                XmlSerializer keySer = XmlTypeAssociator <TKey> .GetSerializer(r);

                XMLSerializeManager.Report("Deserializing Key: " + r.Name);
                TKey key = (TKey)keySer.Deserialize(r);
                readUntilEndElement("key", r);

                r.ReadStartElement("value");
                XmlSerializer valueSer = XmlTypeAssociator <TValue> .GetSerializer(r);

                XMLSerializeManager.Report("Deserializing Value: " + r.Name);
                TValue value = (TValue)valueSer.Deserialize(r);
                readUntilEndElement("value", r);

                Add(key, value);

                r.ReadEndElement();//--item

                r.MoveToContent();
                hasRead = true;
            }
            r.ReadEndElement();//--dictionary
            if (hasRead)
            {
                r.ReadEndElement();
            }
        }
Ejemplo n.º 9
0
 public static T DeserializeObjectFromFile(string file_path)
 {
     return((T)XMLSerializeManager.DeserializeObjectFromFile(file_path, typeof(T)));
 }
Ejemplo n.º 10
0
 public static T DeserializeObject(string xmlStr)
 {
     return((T)XMLSerializeManager.DeserializeObject(xmlStr, typeof(T)));
 }
Ejemplo n.º 11
0
 public static T DeserializeObject(MemoryStream stream)
 {
     return((T)XMLSerializeManager.DeserializeObject(stream, typeof(T)));
 }
Ejemplo n.º 12
0
 public static void SerializeObjectToFile(T obj, string file_path)
 {
     XMLSerializeManager.SerializeObjectToFile(obj, typeof(T), file_path);
 }
Ejemplo n.º 13
0
 public static void SerializeObjectToFile(T obj, string file_path, bool useSafeOverwrite)
 {
     XMLSerializeManager.SerializeObjectToFile(obj, typeof(T), file_path, useSafeOverwrite);
 }
Ejemplo n.º 14
0
 public static MemoryStream SerializeObjectToMemoryStream(T obj)
 {
     return(XMLSerializeManager.SerializeObjectToMemoryStream(obj, typeof(T)));
 }
Ejemplo n.º 15
0
 public static string SerializeObject(T obj)
 {
     return(XMLSerializeManager.SerializeObject(obj, typeof(T)));
 }
Ejemplo n.º 16
0
 public static XmlSerializer GetSerializer(Type t)
 {
     return(XMLSerializeManager.GetSerializer(t));
 }