System.Xml.Serialization.ReflectionXmlSerializationWriter.GenerateTypeElement C# (CSharp) Method

GenerateTypeElement() private method

private GenerateTypeElement ( object o, XmlTypeMapping xmlMapping ) : void
o object
xmlMapping XmlTypeMapping
return void
        private void GenerateTypeElement(object o, XmlTypeMapping xmlMapping)
        {
            ElementAccessor element = xmlMapping.Accessor;
            TypeMapping mapping = element.Mapping;

            WriteStartDocument();
            if (o == null)
            {
                if (element.IsNullable)
                {
                    if (mapping.IsSoap)
                    {
                        throw new PlatformNotSupportedException();
                    }
                    else
                    {
                        WriteNullTagLiteral(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                    }
                }
                else
                {
                    WriteEmptyTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                }

                return;
            }

            if (!mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.GetTypeInfo().IsPrimitive)
            {
                TopLevelElement();
            }

            WriteMember(o, null, new ElementAccessor[] { element }, null, null, mapping.TypeDesc, !element.IsSoap, xmlMapping);

            if (mapping.IsSoap)
            {
                throw new PlatformNotSupportedException();
            }
        }