Exemple #1
0
        private CollectionDataNode ReadUnknownCollectionData(XmlReaderDelegator xmlReader, string dataContractName, string dataContractNamespace)
        {
            XmlNodeType        type;
            CollectionDataNode dataNode = new CollectionDataNode();

            this.InitializeExtensionDataNode(dataNode, dataContractName, dataContractNamespace);
            int arraySZSize = this.attributes.ArraySZSize;

            while ((type = xmlReader.MoveToContent()) != XmlNodeType.EndElement)
            {
                if (type != XmlNodeType.Element)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
                }
                if (dataNode.ItemName == null)
                {
                    dataNode.ItemName      = xmlReader.LocalName;
                    dataNode.ItemNamespace = xmlReader.NamespaceURI;
                }
                if (xmlReader.IsStartElement(dataNode.ItemName, dataNode.ItemNamespace))
                {
                    if (dataNode.Items == null)
                    {
                        dataNode.Items = new List <IDataNode>();
                    }
                    dataNode.Items.Add(this.ReadExtensionDataValue(xmlReader));
                }
                else
                {
                    this.SkipUnknownElement(xmlReader);
                }
            }
            xmlReader.ReadEndElement();
            if (arraySZSize != -1)
            {
                dataNode.Size = arraySZSize;
                if (dataNode.Items == null)
                {
                    if (dataNode.Size > 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("ArraySizeAttributeIncorrect", new object[] { arraySZSize, 0 })));
                    }
                    return(dataNode);
                }
                if (dataNode.Size != dataNode.Items.Count)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("ArraySizeAttributeIncorrect", new object[] { arraySZSize, dataNode.Items.Count })));
                }
                return(dataNode);
            }
            if (dataNode.Items != null)
            {
                dataNode.Size = dataNode.Items.Count;
                return(dataNode);
            }
            dataNode.Size = 0;
            return(dataNode);
        }
 private void MoveNextInCollection(CollectionDataNode dataNode)
 {
     if ((dataNode.Items != null) && (this.element.childElementIndex < dataNode.Items.Count))
     {
         if (this.element.childElementIndex == 0)
         {
             this.context.IncrementItemCount(-dataNode.Items.Count);
         }
         IDataNode node = dataNode.Items[this.element.childElementIndex++];
         this.SetNextElement(node, dataNode.ItemName, dataNode.ItemNamespace, GetPrefix(dataNode.ItemNamespace));
     }
     else
     {
         this.internalNodeType          = ExtensionDataNodeType.EndElement;
         this.element.childElementIndex = 0;
     }
 }
 private void WriteExtensionCollectionData(XmlWriterDelegator xmlWriter, CollectionDataNode dataNode)
 {
     if (!this.TryWriteDeserializedExtensionData(xmlWriter, dataNode))
     {
         this.WriteExtensionDataTypeInfo(xmlWriter, dataNode);
         this.WriteArraySize(xmlWriter, dataNode.Size);
         IList <IDataNode> items = dataNode.Items;
         if (items != null)
         {
             for (int i = 0; i < items.Count; i++)
             {
                 xmlWriter.WriteStartElement(dataNode.ItemName, dataNode.ItemNamespace);
                 this.WriteExtensionDataValue(xmlWriter, items[i]);
                 xmlWriter.WriteEndElement();
             }
         }
     }
 }
Exemple #4
0
        private void MoveNextInCollection(CollectionDataNode dataNode)
        {
            if (dataNode.Items != null && _element.childElementIndex < dataNode.Items.Count)
            {
                if (_element.childElementIndex == 0)
                {
                    _context.IncrementItemCount(-dataNode.Items.Count);
                }

                IDataNode item = dataNode.Items[_element.childElementIndex++];
                SetNextElement(item, dataNode.ItemName, dataNode.ItemNamespace, GetPrefix(dataNode.ItemNamespace));
            }
            else
            {
                _internalNodeType          = ExtensionDataNodeType.EndElement;
                _element.childElementIndex = 0;
            }
        }
        private CollectionDataNode ReadUnknownCollectionData(XmlReaderDelegator xmlReader, string?dataContractName, string?dataContractNamespace)
        {
            Debug.Assert(attributes != null);

            var dataNode = new CollectionDataNode();

            InitializeExtensionDataNode(dataNode, dataContractName, dataContractNamespace);

            int         arraySize = attributes.ArraySZSize;
            XmlNodeType nodeType;

            while ((nodeType = xmlReader.MoveToContent()) != XmlNodeType.EndElement)
            {
                if (nodeType != XmlNodeType.Element)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
                }

                if (dataNode.ItemName == null)
                {
                    dataNode.ItemName      = xmlReader.LocalName;
                    dataNode.ItemNamespace = xmlReader.NamespaceURI;
                }
                if (xmlReader.IsStartElement(dataNode.ItemName, dataNode.ItemNamespace !))
                {
                    dataNode.Items ??= new List <IDataNode?>();
                    dataNode.Items.Add(ReadExtensionDataValue(xmlReader));
                }
                else
                {
                    SkipUnknownElement(xmlReader);
                }
            }
            xmlReader.ReadEndElement();

            if (arraySize != -1)
            {
                dataNode.Size = arraySize;
                if (dataNode.Items == null)
                {
                    if (dataNode.Size > 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArraySizeAttributeIncorrect, arraySize, 0)));
                    }
                }
                else if (dataNode.Size != dataNode.Items.Count)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArraySizeAttributeIncorrect, arraySize, dataNode.Items.Count)));
                }
            }
            else
            {
                if (dataNode.Items != null)
                {
                    dataNode.Size = dataNode.Items.Count;
                }
                else
                {
                    dataNode.Size = 0;
                }
            }

            return(dataNode);
        }