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

WriteMember() private method

private WriteMember ( object memberValue, AttributeAccessor attribute, TypeDesc memberTypeDesc, object parent ) : void
memberValue object
attribute AttributeAccessor
memberTypeDesc TypeDesc
parent object
return void
        private void WriteMember(object memberValue, AttributeAccessor attribute, TypeDesc memberTypeDesc, object parent)
        {
            if (memberTypeDesc.IsAbstract) return;
            if (memberTypeDesc.IsArrayLike)
            {
                var sb = new StringBuilder();
                TypeDesc arrayElementTypeDesc = memberTypeDesc.ArrayElementTypeDesc;
                bool canOptimizeWriteListSequence = CanOptimizeWriteListSequence(arrayElementTypeDesc);
                if (attribute.IsList)
                {
                    if (canOptimizeWriteListSequence)
                    {
                        Writer.WriteStartAttribute(null, attribute.Name, attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : String.Empty);
                    }
                }

                var a = memberValue as IEnumerable;

                // #10593: Add More Tests for Serialization Code
                Debug.Assert(a != null);

                var e = a.GetEnumerator();
                bool shouldAppendWhitespace = false;
                if (e != null)
                {
                    while (e.MoveNext())
                    {
                        object ai = e.Current;

                        if (attribute.IsList)
                        {
                            string stringValue;
                            if (attribute.Mapping is EnumMapping)
                            {
                                stringValue = WriteEnumMethod((EnumMapping)attribute.Mapping, ai);
                            }
                            else
                            {
                                if (!WritePrimitiveValue(arrayElementTypeDesc, ai, true, out stringValue))
                                {
                                    // #10593: Add More Tests for Serialization Code
                                    Debug.Assert(ai is byte[]);
                                }
                            }

                            // check to see if we can write values of the attribute sequentially
                            if (canOptimizeWriteListSequence)
                            {
                                if (shouldAppendWhitespace)
                                {
                                    Writer.WriteString(" ");
                                }

                                if (ai is byte[])
                                {
                                    WriteValue((byte[])ai);
                                }
                                else
                                {
                                    WriteValue(stringValue);
                                }
                            }
                            else
                            {
                                if (shouldAppendWhitespace)
                                {
                                    sb.Append(" ");
                                }

                                sb.Append(stringValue);
                            }
                        }
                        else
                        {
                            WriteAttribute(ai, attribute, parent);
                        }

                        shouldAppendWhitespace = true;
                    }

                    if (attribute.IsList)
                    {
                        // check to see if we can write values of the attribute sequentially
                        if (canOptimizeWriteListSequence)
                        {
                            Writer.WriteEndAttribute();
                        }
                        else
                        {
                            if (sb.Length != 0)
                            {
                                string ns = attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : String.Empty;
                                WriteAttribute(attribute.Name, ns, sb.ToString());
                            }
                        }
                    }
                }
            }
            else
            {
                WriteAttribute(memberValue, attribute, parent);
            }
        }

Same methods

ReflectionXmlSerializationWriter::WriteMember ( object o, object choiceSource, ElementAccessor elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors, XmlMapping parentMapping = null ) : void