protected virtual void WriteObject(XmlTypeMapping typeMap, object ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
        {
            if (ob == null)
            {
                if (isNullable)
                {
                    if (_format == SerializationFormat.Literal)
                    {
                        WriteNullTagLiteral(element, namesp);
                    }
                    else
                    {
                        WriteNullTagEncoded(element, namesp);
                    }
                }
                return;
            }

            if (ob is XmlNode)
            {
                if (_format == SerializationFormat.Literal)
                {
                    WriteElementLiteral((XmlNode)ob, "", "", true, typeMap.IsAny);
                }
                else
                {
                    WriteElementEncoded((XmlNode)ob, "", "", true, typeMap.IsAny);
                }
                return;
            }

            if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
            {
                WriteSerializable((IXmlSerializable)ob, element, namesp, isNullable, !typeMap.IsAny);
                return;
            }

            XmlTypeMapping map = typeMap.GetRealTypeMap(ob.GetType());

            if (map == null)
            {
                // bug #81539
                if (ob.GetType().IsArray&& typeof(XmlNode).IsAssignableFrom(ob.GetType().GetElementType()))
                {
                    Writer.WriteStartElement(element, namesp);
                    foreach (XmlNode node in (IEnumerable)ob)
                    {
                        node.WriteTo(Writer);
                    }
                    Writer.WriteEndElement();
                }
                else
                {
                    WriteTypedPrimitive(element, namesp, ob, true);
                }
                return;
            }

            if (writeWrappingElem)
            {
                if (map != typeMap || _format == SerializationFormat.Encoded)
                {
                    needType = true;
                }
                WriteStartElement(element, namesp, ob);
            }

            if (needType)
            {
                WriteXsiType(map.XmlType, map.XmlTypeNamespace);
            }

            switch (map.TypeData.SchemaType)
            {
            case SchemaTypes.Class: WriteObjectElement(map, ob, element, namesp); break;

            case SchemaTypes.Array: WriteListElement(map, ob, element, namesp); break;

            case SchemaTypes.Primitive: WritePrimitiveElement(map, ob, element, namesp); break;

            case SchemaTypes.Enum: WriteEnumElement(map, ob, element, namesp); break;
            }

            if (writeWrappingElem)
            {
                WriteEndElement(ob);
            }
        }
		protected virtual void WriteObject (XmlTypeMapping typeMap, object ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
		{
			if (ob == null)
			{
				if (isNullable) 
				{
					if (_format == SerializationFormat.Literal) WriteNullTagLiteral(element, namesp);
					else WriteNullTagEncoded (element, namesp);
				}
				return;
			}

			if (ob is XmlNode)
			{
				if (_format == SerializationFormat.Literal) WriteElementLiteral((XmlNode)ob, "", "", true, false);
				else WriteElementEncoded((XmlNode)ob, "", "", true, false);
				return;
			}

			if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
			{
				WriteSerializable ((IXmlSerializable)ob, element, namesp, isNullable);
				return;
			}

			XmlTypeMapping map = typeMap.GetRealTypeMap (ob.GetType());

			if (map == null) 
			{
				// bug #81539
				if (ob.GetType ().IsArray && typeof (XmlNode).IsAssignableFrom (ob.GetType ().GetElementType ())) {
					Writer.WriteStartElement (element, namesp);
					foreach (XmlNode node in (IEnumerable) ob)
						node.WriteTo (Writer);
					Writer.WriteEndElement ();
				}
				else
					WriteTypedPrimitive (element, namesp, ob, true);
				return;
			}

			if (writeWrappingElem)
			{
				if (map != typeMap || _format == SerializationFormat.Encoded) needType = true;
				WriteStartElement (element, namesp, ob);
			}

			if (needType) 
				WriteXsiType(map.XmlType, map.XmlTypeNamespace);

			switch (map.TypeData.SchemaType)
			{
				case SchemaTypes.Class: WriteObjectElement (map, ob, element, namesp); break;
				case SchemaTypes.Array: WriteListElement (map, ob, element, namesp); break;
				case SchemaTypes.Primitive: WritePrimitiveElement (map, ob, element, namesp); break;
				case SchemaTypes.Enum: WriteEnumElement (map, ob, element, namesp); break;
			}

			if (writeWrappingElem)
				WriteEndElement (ob);
		}
Exemple #3
0
        protected virtual void WriteObject(XmlTypeMapping typeMap, object ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
        {
            if (ob == null)
            {
                if (isNullable)
                {
                    if (this._format == SerializationFormat.Literal)
                    {
                        base.WriteNullTagLiteral(element, namesp);
                    }
                    else
                    {
                        base.WriteNullTagEncoded(element, namesp);
                    }
                }
                return;
            }
            if (ob is XmlNode)
            {
                if (this._format == SerializationFormat.Literal)
                {
                    base.WriteElementLiteral((XmlNode)ob, string.Empty, string.Empty, true, false);
                }
                else
                {
                    base.WriteElementEncoded((XmlNode)ob, string.Empty, string.Empty, true, false);
                }
                return;
            }
            if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
            {
                base.WriteSerializable((IXmlSerializable)ob, element, namesp, isNullable);
                return;
            }
            XmlTypeMapping realTypeMap = typeMap.GetRealTypeMap(ob.GetType());

            if (realTypeMap == null)
            {
                if (ob.GetType().IsArray&& typeof(XmlNode).IsAssignableFrom(ob.GetType().GetElementType()))
                {
                    base.Writer.WriteStartElement(element, namesp);
                    foreach (object obj in ((IEnumerable)ob))
                    {
                        XmlNode xmlNode = (XmlNode)obj;
                        xmlNode.WriteTo(base.Writer);
                    }
                    base.Writer.WriteEndElement();
                }
                else
                {
                    base.WriteTypedPrimitive(element, namesp, ob, true);
                }
                return;
            }
            if (writeWrappingElem)
            {
                if (realTypeMap != typeMap || this._format == SerializationFormat.Encoded)
                {
                    needType = true;
                }
                base.WriteStartElement(element, namesp, ob);
            }
            if (needType)
            {
                base.WriteXsiType(realTypeMap.XmlType, realTypeMap.XmlTypeNamespace);
            }
            switch (realTypeMap.TypeData.SchemaType)
            {
            case SchemaTypes.Primitive:
                this.WritePrimitiveElement(realTypeMap, ob, element, namesp);
                break;

            case SchemaTypes.Enum:
                this.WriteEnumElement(realTypeMap, ob, element, namesp);
                break;

            case SchemaTypes.Array:
                this.WriteListElement(realTypeMap, ob, element, namesp);
                break;

            case SchemaTypes.Class:
                this.WriteObjectElement(realTypeMap, ob, element, namesp);
                break;
            }
            if (writeWrappingElem)
            {
                base.WriteEndElement(ob);
            }
        }