Ejemplo n.º 1
0
 private void WriteSpecialMapping(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member)
 {
     WriteStartElement(writer, component, name, ns, member);
     WriteSpecialContent(writer, obj);
     writer.WriteEndElement();
 }
Ejemplo n.º 2
0
        private void WriteObjectContent(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, int nestingLevel)
        {
            TypeMapping typeMapping = TypeMapper.GetTypeMapping(GetSerializationType(obj));

            if (name == null)
            {
                name = typeMapping.Name;
                ns   = typeMapping.Namespace;
            }
            if (typeMapping is PrimitiveMapping)
            {
                WritePrimitive(writer, component, obj, name, ns, member, typeMapping);
            }
            else if (typeMapping is ArrayMapping)
            {
                WriteArray(writer, component, obj, name, ns, member, (ArrayMapping)typeMapping, nestingLevel);
            }
            else if (typeMapping is SpecialMapping)
            {
                WriteSpecialMapping(writer, component, obj, name, ns, member);
            }
            else if (typeMapping is StructMapping)
            {
                WriteStructure(writer, component, obj, name, ns, member, (StructMapping)typeMapping);
            }
        }
Ejemplo n.º 3
0
 private void WriteStartElement(XmlWriter writer, object component, string name, string ns, MemberMapping member)
 {
     writer.WriteStartElement(name, ns);
     if (component == null || member == null || member.ChildAttributes == null)
     {
         return;
     }
     foreach (MemberMapping childAttribute in member.ChildAttributes)
     {
         WriteChildAttribute(writer, childAttribute.GetValue(component), childAttribute);
     }
 }
Ejemplo n.º 4
0
 private void WriteStructure(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, StructMapping mapping)
 {
     if (obj != null)
     {
         WriteStartElement(writer, component, name, ns, member);
         WriteStructContent(writer, obj, mapping, ns);
         writer.WriteEndElement();
     }
 }
Ejemplo n.º 5
0
 private void WriteObject(XmlWriter writer, object obj, string name, string ns, MemberMapping member, int nestingLevel)
 {
     if (obj != null && (!(obj is IShouldSerialize) || ((IShouldSerialize)obj).ShouldSerializeThis()))
     {
         WriteObjectContent(writer, null, obj, name, ns, member, nestingLevel);
     }
 }
Ejemplo n.º 6
0
 private void WriteArray(XmlWriter writer, object component, object array, string name, string ns, MemberMapping member, ArrayMapping mapping, int nestingLevel)
 {
     if (ShouldSerializeArray(array))
     {
         WriteStartElement(writer, component, name, ns, member);
         WriteArrayContent(writer, array, mapping, member, nestingLevel, ns);
         writer.WriteEndElement();
     }
 }
Ejemplo n.º 7
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 = 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)
                {
                    WriteObject(writer, item, text, ns, member, nestingLevel + 1);
                }
                else if (flag)
                {
                    WriteNilElement(writer, text, ns);
                }
            }
        }
Ejemplo n.º 8
0
 private void WritePrimitive(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, TypeMapping mapping)
 {
     WriteStartElement(writer, component, name, ns, member);
     WritePrimitiveContent(writer, mapping, obj);
     writer.WriteEndElement();
 }
Ejemplo n.º 9
0
        private void ReadStructContent(object obj, StructMapping mapping)
        {
            m_reader.MoveToContent();
            string name         = m_reader.Name;
            string namespaceURI = m_reader.NamespaceURI;

            ReadStructAttributes(obj, mapping);
            if (m_reader.IsEmptyElement)
            {
                m_reader.Skip();
                return;
            }
            m_reader.ReadStartElement();
            m_reader.MoveToContent();
            while (m_reader.NodeType != XmlNodeType.EndElement && m_reader.NodeType != 0)
            {
                string localName     = m_reader.LocalName;
                string namespaceURI2 = m_reader.NamespaceURI;
                namespaceURI2 = ((namespaceURI == namespaceURI2) ? string.Empty : namespaceURI2);
                MemberMapping memberMapping = mapping.GetElement(localName, namespaceURI2);
                Type          type          = null;
                if (memberMapping != null)
                {
                    type = memberMapping.Type;
                }
                else
                {
                    List <MemberMapping> typeNameElements = mapping.GetTypeNameElements();
                    if (typeNameElements != null)
                    {
                        bool flag = false;
                        for (int i = 0; i < typeNameElements.Count; i++)
                        {
                            memberMapping = typeNameElements[i];
                            XmlElementAttributes xmlElements = memberMapping.XmlAttributes.XmlElements;
                            if (base.XmlOverrides != null)
                            {
                                XmlAttributes xmlAttributes = base.XmlOverrides[obj.GetType()];
                                if (xmlAttributes == null)
                                {
                                    xmlAttributes = base.XmlOverrides[memberMapping.Type];
                                }
                                if (xmlAttributes != null && xmlAttributes.XmlElements != null)
                                {
                                    xmlElements = xmlAttributes.XmlElements;
                                }
                            }
                            foreach (XmlElementAttribute item in xmlElements)
                            {
                                if (item.ElementName == localName && item.Type != null)
                                {
                                    type = item.Type;
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                break;
                            }
                        }
                    }
                }
                if (type != null)
                {
                    if (memberMapping.ChildAttributes != null)
                    {
                        foreach (MemberMapping childAttribute in memberMapping.ChildAttributes)
                        {
                            ReadChildAttribute(obj, mapping, childAttribute);
                        }
                    }
                    if (memberMapping.IsReadOnly)
                    {
                        if (!TypeMapper.IsPrimitiveType(type))
                        {
                            object value = memberMapping.GetValue(obj);
                            if (value != null)
                            {
                                ReadObjectContent(value, memberMapping, 0);
                            }
                            else
                            {
                                m_reader.Skip();
                            }
                        }
                        else
                        {
                            m_reader.Skip();
                        }
                    }
                    else
                    {
                        object obj2 = ReadObject(type, memberMapping, 0);
                        if (obj2 != null)
                        {
                            memberMapping.SetValue(obj, obj2);
                        }
                    }
                }
                else
                {
                    if (namespaceURI2 != string.Empty && m_validNamespaces.Contains(namespaceURI2))
                    {
                        IXmlLineInfo xmlLineInfo = (IXmlLineInfo)m_reader;
                        throw new XmlException(RDLValidatingReaderStrings.rdlValidationInvalidMicroVersionedElement(m_reader.Name, name, xmlLineInfo.LineNumber.ToString(CultureInfo.InvariantCulture.NumberFormat), xmlLineInfo.LinePosition.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                    }
                    m_reader.Skip();
                }
                m_reader.MoveToContent();
            }
            m_reader.ReadEndElement();
        }
Ejemplo n.º 10
0
        private object ReadArrayContent(object array, ArrayMapping mapping, MemberMapping member, int nestingLevel)
        {
            IList list = (IList)array;

            if (m_reader.IsEmptyElement)
            {
                m_reader.Skip();
            }
            else
            {
                m_reader.ReadStartElement();
                m_reader.MoveToContent();
                while (m_reader.NodeType != XmlNodeType.EndElement && m_reader.NodeType != 0)
                {
                    if (m_reader.NodeType == XmlNodeType.Element)
                    {
                        string localName = m_reader.LocalName;
                        _ = m_reader.NamespaceURI;
                        Type value = 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];
                                value = 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 value);
                            }
                            else
                            {
                                foreach (XmlElementAttribute item in xmlElementAttributes)
                                {
                                    if (localName == item.ElementName)
                                    {
                                        value = item.Type;
                                        break;
                                    }
                                }
                            }
                        }
                        if (value != null)
                        {
                            object value2;
                            if (flag && m_reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance") == "true")
                            {
                                m_reader.Skip();
                                value2 = null;
                            }
                            else
                            {
                                value2 = ReadObject(value, member, nestingLevel + 1);
                            }
                            list.Add(value2);
                        }
                        else
                        {
                            m_reader.Skip();
                        }
                    }
                    else
                    {
                        m_reader.Skip();
                    }
                    m_reader.MoveToContent();
                }
                m_reader.ReadEndElement();
            }
            return(array);
        }