コード例 #1
0
        private void ReadStructContent(object obj, StructMapping mapping)
        {
            this.m_reader.MoveToContent();
            string name         = this.m_reader.Name;
            string namespaceURI = this.m_reader.NamespaceURI;

            this.ReadStructAttributes(obj, mapping);
            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)
                {
                    string localName     = this.m_reader.LocalName;
                    string namespaceURI2 = this.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)
                            {
                                this.ReadChildAttribute(obj, mapping, childAttribute);
                            }
                        }
                        if (memberMapping.IsReadOnly)
                        {
                            if (!TypeMapper.IsPrimitiveType(type))
                            {
                                object value = memberMapping.GetValue(obj);
                                if (value != null)
                                {
                                    this.ReadObjectContent(value, memberMapping, 0);
                                }
                                else
                                {
                                    this.m_reader.Skip();
                                }
                            }
                            else
                            {
                                this.m_reader.Skip();
                            }
                        }
                        else
                        {
                            object obj2 = this.ReadObject(type, memberMapping, 0);
                            if (obj2 != null)
                            {
                                memberMapping.SetValue(obj, obj2);
                            }
                        }
                    }
                    else
                    {
                        if (namespaceURI2 != string.Empty && this.m_validNamespaces.Contains(namespaceURI2))
                        {
                            IXmlLineInfo xmlLineInfo = (IXmlLineInfo)this.m_reader;
                            string       message     = RDLValidatingReaderStrings.rdlValidationInvalidMicroVersionedElement(this.m_reader.Name, name, xmlLineInfo.LineNumber.ToString(CultureInfo.InvariantCulture.NumberFormat), xmlLineInfo.LinePosition.ToString(CultureInfo.InvariantCulture.NumberFormat));
                            throw new XmlException(message);
                        }
                        this.m_reader.Skip();
                    }
                    this.m_reader.MoveToContent();
                }
                this.m_reader.ReadEndElement();
            }
        }
コード例 #2
0
 private void WriteSpecialMapping(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member)
 {
     this.WriteStartElement(writer, component, name, ns, member);
     this.WriteSpecialContent(writer, obj);
     writer.WriteEndElement();
 }
コード例 #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);
        }
コード例 #4
0
        private void WriteObjectContent(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, int nestingLevel)
        {
            Type        serializationType = base.GetSerializationType(obj);
            TypeMapping typeMapping       = TypeMapper.GetTypeMapping(serializationType);

            if (name == null)
            {
                name = typeMapping.Name;
                ns   = typeMapping.Namespace;
            }
            if (typeMapping is PrimitiveMapping)
            {
                this.WritePrimitive(writer, component, obj, name, ns, member, typeMapping);
            }
            else if (typeMapping is ArrayMapping)
            {
                this.WriteArray(writer, component, obj, name, ns, member, (ArrayMapping)typeMapping, nestingLevel);
            }
            else if (typeMapping is SpecialMapping)
            {
                this.WriteSpecialMapping(writer, component, obj, name, ns, member);
            }
            else if (typeMapping is StructMapping)
            {
                this.WriteStructure(writer, component, obj, name, ns, member, (StructMapping)typeMapping);
            }
        }
コード例 #5
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)
     {
         foreach (MemberMapping childAttribute in member.ChildAttributes)
         {
             this.WriteChildAttribute(writer, childAttribute.GetValue(component), childAttribute);
         }
     }
 }
コード例 #6
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()))
     {
         this.WriteObjectContent(writer, null, obj, name, ns, member, nestingLevel);
     }
 }
コード例 #7
0
 private void WriteStructure(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, StructMapping mapping)
 {
     if (obj != null)
     {
         this.WriteStartElement(writer, component, name, ns, member);
         this.WriteStructContent(writer, obj, mapping, ns);
         writer.WriteEndElement();
     }
 }
コード例 #8
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();
     }
 }
コード例 #9
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);
                }
            }
        }
コード例 #10
0
 private void WritePrimitive(XmlWriter writer, object component, object obj, string name, string ns, MemberMapping member, TypeMapping mapping)
 {
     this.WriteStartElement(writer, component, name, ns, member);
     this.WritePrimitiveContent(writer, mapping, obj);
     writer.WriteEndElement();
 }