Exemplo n.º 1
0
        private ICustomXmlSerializer TryGetCustomSerializer(object element)
        {
            if (this.Mode != WindowProfileSerializerMode.Custom)
            {
                return((ICustomXmlSerializer)null);
            }
            ICustomXmlSerializable customXmlSerializable = element as ICustomXmlSerializable;

            if (customXmlSerializable == null)
            {
                return((ICustomXmlSerializer)null);
            }
            return(customXmlSerializable.CreateSerializer());
        }
Exemplo n.º 2
0
        private void SerializeInternal(object element, XmlWriter writer, bool isRootElement)
        {
            if (element == null)
            {
                return;
            }
            ICustomXmlSerializer customXmlSerializer = (ICustomXmlSerializer)null;

            if (this.Mode == WindowProfileSerializerMode.Custom)
            {
                ICustomXmlSerializable customXmlSerializable = element as ICustomXmlSerializable;
                if (customXmlSerializable != null)
                {
                    customXmlSerializer = customXmlSerializable.CreateSerializer();
                    if (customXmlSerializer == null)
                    {
                        return;
                    }
                }
            }
            Type type = element.GetType();

            if (this.Mode == WindowProfileSerializerMode.Reflection && WindowProfileSerializer.IsTypeNonSerializable(type))
            {
                return;
            }
            if (WindowProfileSerializer.IsSequenceType(type))
            {
                this.SerializeSequence(element as IEnumerable, writer);
            }
            else
            {
                if (this.GetPrefix(type) != null)
                {
                    writer.WriteStartElement(this.GetPrefix(type), type.Name, this.GetClrNamespace(type));
                }
                else
                {
                    writer.WriteStartElement(type.Name, this.GetClrNamespace(type));
                }
                if (isRootElement)
                {
                    this.WriteNamespaceDeclarations(writer);
                }
                object contentPropertyValue = (object)null;
                IEnumerable <KeyValuePair <string, object> > enumerable;
                if (customXmlSerializer != null)
                {
                    customXmlSerializer.WriteXmlAttributes(writer);
                    enumerable           = customXmlSerializer.GetNonContentPropertyValues();
                    contentPropertyValue = customXmlSerializer.Content;
                }
                else
                {
                    enumerable = (IEnumerable <KeyValuePair <string, object> >)WindowProfileSerializer.GetChildPropertiesAndContent(element, writer, type, ref contentPropertyValue);
                }
                foreach (KeyValuePair <string, object> keyValuePair in enumerable)
                {
                    string localName = type.Name + "." + keyValuePair.Key;
                    if (this.GetPrefix(type) != null)
                    {
                        writer.WriteStartElement(this.GetPrefix(type), localName, this.GetClrNamespace(type));
                    }
                    else
                    {
                        writer.WriteStartElement(localName, this.GetClrNamespace(type));
                    }
                    this.SerializeInternal(keyValuePair.Value, writer, false);
                    writer.WriteEndElement();
                }
                if (contentPropertyValue != null)
                {
                    this.SerializeInternal(contentPropertyValue, writer, false);
                }
                writer.WriteEndElement();
            }
        }