Exemplo n.º 1
0
        private void WriteArrayContent(XmlWriter writer, object array, ArrayMapping mapping, MemberMapping member, int nestingLevel, string ns)
        {
            Dictionary <string, Type> elementTypes = mapping.ElementTypes;

            foreach (object item in (IEnumerable)array)
            {
                string text = null;
                bool   flag = false;
                if (member != null && member.XmlAttributes.XmlArrayItems.Count > nestingLevel)
                {
                    XmlArrayItemAttribute xmlArrayItemAttribute = member.XmlAttributes.XmlArrayItems[nestingLevel];
                    text = xmlArrayItemAttribute.ElementName;
                    flag = xmlArrayItemAttribute.IsNullable;
                }
                else
                {
                    Type        serializationType = base.GetSerializationType(item);
                    TypeMapping typeMapping       = TypeMapper.GetTypeMapping(serializationType);
                    if (typeMapping != null)
                    {
                        text = typeMapping.Name;
                        ns   = typeMapping.Namespace;
                    }
                    else
                    {
                        foreach (KeyValuePair <string, Type> item2 in elementTypes)
                        {
                            if (item2.Value == serializationType)
                            {
                                text = item2.Key;
                                break;
                            }
                        }
                    }
                }
                if (text == null)
                {
                    throw new Exception("No array element name.");
                }
                if (item != null)
                {
                    this.WriteObject(writer, item, text, ns, member, nestingLevel + 1);
                }
                else if (flag)
                {
                    this.WriteNilElement(writer, text, ns);
                }
            }
        }
Exemplo n.º 2
0
        private static ArrayMapping ImportArrayMapping(Type type)
        {
            ArrayMapping arrayMapping = new ArrayMapping(type);

            arrayMapping.ElementTypes = new Dictionary <string, Type>();
            if (type.IsArray)
            {
                Type type2 = arrayMapping.ItemType = type.GetElementType();
                arrayMapping.ElementTypes.Add(type2.Name, type2);
            }
            else
            {
                TypeMapper.GetCollectionElementTypes(type, arrayMapping);
            }
            return(arrayMapping);
        }
Exemplo n.º 3
0
        private object ReadArrayContent(object array, ArrayMapping mapping, MemberMapping member, int nestingLevel)
        {
            IList list = (IList)array;

            if (this.m_reader.IsEmptyElement)
            {
                this.m_reader.Skip();
            }
            else
            {
                this.m_reader.ReadStartElement();
                this.m_reader.MoveToContent();
                while (this.m_reader.NodeType != XmlNodeType.EndElement && this.m_reader.NodeType != 0)
                {
                    if (this.m_reader.NodeType == XmlNodeType.Element)
                    {
                        string localName    = this.m_reader.LocalName;
                        string namespaceURI = this.m_reader.NamespaceURI;
                        Type   type         = null;
                        bool   flag         = false;
                        if (member != null && member.XmlAttributes.XmlArrayItems.Count > nestingLevel)
                        {
                            if (localName == member.XmlAttributes.XmlArrayItems[nestingLevel].ElementName)
                            {
                                XmlArrayItemAttribute xmlArrayItemAttribute = member.XmlAttributes.XmlArrayItems[nestingLevel];
                                type = xmlArrayItemAttribute.Type;
                                flag = xmlArrayItemAttribute.IsNullable;
                            }
                        }
                        else
                        {
                            XmlElementAttributes xmlElementAttributes = null;
                            if (base.XmlOverrides != null)
                            {
                                XmlAttributes xmlAttributes = base.XmlOverrides[mapping.ItemType];
                                if (xmlAttributes != null && xmlAttributes.XmlElements != null)
                                {
                                    xmlElementAttributes = xmlAttributes.XmlElements;
                                }
                            }
                            if (xmlElementAttributes == null)
                            {
                                mapping.ElementTypes.TryGetValue(localName, out type);
                            }
                            else
                            {
                                foreach (XmlElementAttribute item in xmlElementAttributes)
                                {
                                    if (localName == item.ElementName)
                                    {
                                        type = item.Type;
                                        break;
                                    }
                                }
                            }
                        }
                        if (type != null)
                        {
                            object value;
                            if (flag && this.m_reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance") == "true")
                            {
                                this.m_reader.Skip();
                                value = null;
                            }
                            else
                            {
                                value = this.ReadObject(type, member, nestingLevel + 1);
                            }
                            list.Add(value);
                        }
                        else
                        {
                            this.m_reader.Skip();
                        }
                    }
                    else
                    {
                        this.m_reader.Skip();
                    }
                    this.m_reader.MoveToContent();
                }
                this.m_reader.ReadEndElement();
            }
            return(array);
        }
Exemplo n.º 4
0
 private void WriteArray(XmlWriter writer, object component, object array, string name, string ns, MemberMapping member, ArrayMapping mapping, int nestingLevel)
 {
     if (this.ShouldSerializeArray(array))
     {
         this.WriteStartElement(writer, component, name, ns, member);
         this.WriteArrayContent(writer, array, mapping, member, nestingLevel, ns);
         writer.WriteEndElement();
     }
 }