Ejemplo n.º 1
0
        /****************************************************************************/
        public virtual void SerializeProperty(cXMLWriter objWriter, object objInstance, PropertyInfo objProperty)
        {
            if (m_eAttributes != Attributes.DeserializeOnly)
            {
                string strElementName = this.ElementName;

                if (strElementName == "")
                {
                    strElementName = objProperty.Name;
                }

                string strValue = objProperty.GetValue(objInstance, null).Normalized();

                if (m_bForceType)
                {
                    using (new XmlElementWriter(objWriter, strElementName))
                    {
                        objWriter.WriteAttributeString("type", objProperty.PropertyType.ToString().ToLower().Replace("system.", ""));
                        objWriter.WriteString(strValue);
                    }
                }
                else
                {
                    objWriter.WriteElementString(strElementName, strValue);
                }
            }
        }
Ejemplo n.º 2
0
        /****************************************************************************/
        public static XmlDocument ToXml(this XPathNodeIterator iterator)
        {
            cXMLWriter xmlResults = new cXMLWriter();

            xmlResults.WriteStartDocument();
            xmlResults.Write(iterator);
            xmlResults.WriteEndDocument();

            return(xmlResults.Xml);
        }
Ejemplo n.º 3
0
        /****************************************************************************/
        private static void SerializeChildren(cXMLWriter objWriter, object objInstance)
        {
            Type objType = objInstance.GetType();

            PropertyInfo[]           aProperties = objType.GetProperties(); // ??? TODO: Let's revisit the filter some other time
            List <SerializeProperty> aAttributes = new List <SerializeProperty>();
            List <SerializeProperty> aLists      = new List <SerializeProperty>();
            List <SerializeProperty> aElements   = new List <SerializeProperty>();

            // Gather all the properties that have an XmlSerialize attribute
            foreach (PropertyInfo objProperty in aProperties)
            {
                XmlSerialize objAttribute = XmlSerialize.GetSerializeAttribute(objProperty);

                if (objAttribute != null)
                {
                    SerializeProperty objProp = new SerializeProperty(objProperty, objAttribute);

                    // Put into the right bucket
                    if (objAttribute is XmlAttributeSerialize)
                    {
                        aAttributes.Add(objProp);
                    }
                    else if (objAttribute is XmlSerializeList)
                    {
                        aLists.Add(objProp);
                    }
                    else
                    {
                        aElements.Add(objProp);
                    }
                }
            }

            // Write out the xml attributes first
            foreach (SerializeProperty objProperty in aAttributes)
            {
                objProperty.Attribute.SerializeProperty(objWriter, objInstance, objProperty.Property);
            }

            // Now write out all of the elements
            foreach (SerializeProperty objProperty in aElements)
            {
                objProperty.Attribute.SerializeProperty(objWriter, objInstance, objProperty.Property);
            }

            // Now write out all of the lists
            foreach (SerializeProperty objProperty in aLists)
            {
                objProperty.Attribute.SerializeProperty(objWriter, objInstance, objProperty.Property);
            }

            return;
        }
Ejemplo n.º 4
0
        /****************************************************************************/
        public override void SerializeProperty(cXMLWriter objWriter, object objInstance, PropertyInfo objProperty)
        {
            IEnumerable aList = objProperty.GetValue(objInstance, null) as IEnumerable;

            using (XmlElementWriter w = new XmlElementWriter(objWriter, "List"))
            {
                objWriter.WriteAttributeString("name", this.ElementName);

                SerializeList(objWriter, aList);
            }
        }
Ejemplo n.º 5
0
        /****************************************************************************/
        private static void Serialize(cXMLWriter objWriter, object objInstance)
        {
            if (objInstance is IXmlSerialize)
            {
                (objInstance as IXmlSerialize).Serialize(objWriter);
                return;
            }

            Type         objType      = objInstance.GetType();
            XmlSerialize objAttribute = XmlSerialize.GetSerializeAttribute(objType);

            Serialize(objWriter, objInstance, objAttribute);

            return;
        }
Ejemplo n.º 6
0
        /****************************************************************************/
        public static XmlDocument Serialize(object objData)
        {
            cXMLWriter objWriter = new cXMLWriter();

            using (objWriter.Acquire)
            {
                Serialize(objWriter, objData);
            }

            XmlDocument xmlResults = objWriter.Xml;

            //DebugConsole.WriteLine(xmlResults.OuterXml);

            return(xmlResults);
        }
Ejemplo n.º 7
0
        /****************************************************************************/
        public override void SerializeProperty(cXMLWriter objWriter, object objInstance, PropertyInfo objProperty)
        {
            IEnumerable aList = objProperty.GetValue(objInstance, null) as IEnumerable;

            if (this.ElementName != "")
            {
                using (XmlElementWriter w = new XmlElementWriter(objWriter, this.ElementName))
                {
                    SerializeList(objWriter, aList);
                }
            }
            else
            {
                SerializeList(objWriter, aList);
            }
        }
Ejemplo n.º 8
0
        /****************************************************************************/
        public override void SerializeProperty(cXMLWriter objWriter, object objInstance, PropertyInfo objProperty)
        {
            if (m_eAttributes != Attributes.DeserializeOnly)
            {
                string strAttributeName = this.ElementName;

                if (strAttributeName == "")
                {
                    strAttributeName = objProperty.Name;
                }

                string strValue = objProperty.GetValue(objInstance, null).Normalized();

                objWriter.WriteAttributeString(strAttributeName, strValue);
            }
        }
Ejemplo n.º 9
0
        /****************************************************************************/
        public static void Serialize(cXMLWriter objWriter, object objInstance, XmlSerialize objAttribute)
        {
            Type   objType        = objInstance.GetType();
            string strElementName = objType.Name;

            if (objAttribute != null && objAttribute.ElementName != "")
            {
                strElementName = objAttribute.ElementName;
            }

            using (XmlElementWriter w = new XmlElementWriter(objWriter, strElementName))
            {
                SerializeChildren(objWriter, objInstance);
            }

            return;
        }
Ejemplo n.º 10
0
        /****************************************************************************/
        protected void SerializeList(cXMLWriter objWriter, IEnumerable aList)
        {
            foreach (object objChild in aList)
            {
                if (objChild is IXmlSerialize)
                {
                    (objChild as IXmlSerialize).Serialize(objWriter);
                }
                else
                {
                    Type         objType      = objChild.GetType();
                    XmlSerialize objAttribute = XmlSerialize.GetSerializeAttribute(objType);

                    if (!this.XmlSerializeOnly || objAttribute != null)
                    {
                        XmlSerializer.Serialize(objWriter, objChild, objAttribute);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /****************************************************************************/
 public XmlElementWriter(cXMLWriter objWriter, string strName)
 {
     objWriter.WriteStartElement(strName);
     m_objWriter = objWriter;
 }