Esempio n. 1
0
        /****************************************************************************/
        private static void DeserializeChildren(XmlNode xmlData, object objInstance)
        {
            Type objType = objInstance.GetType();

            PropertyInfo[] aProperties = objType.GetProperties(); // ??? TODO: Let's revisit the filter some other time

            foreach (PropertyInfo objProperty in aProperties)
            {
                try
                {
                    XmlSerialize objAttribute = XmlSerialize.GetSerializeAttribute(objProperty);

                    if (objAttribute != null)
                    {
                        objAttribute.DeserializeProperty(xmlData, objInstance, objProperty);
                    }
                }
                catch (Exception ex)
                {
                    cDebug.Capture(ex);
                }
            }

            return;
        }
Esempio n. 2
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;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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);
                    }
                }
            }
        }