Esempio n. 1
0
        public ICollection Read(XmlReader xmlReader)
        {
            if (xmlReader == null)
            {
                throw new ArgumentNullException(nameof(xmlReader));
            }
            ICollectionWrapper result = null;

            if (xmlReader.MoveToContent() == XmlNodeType.Element)
            {
                while (xmlReader.NodeType != XmlNodeType.EndElement && xmlReader.NodeType != XmlNodeType.None)
                {
                    if (xmlReader.IsStartElement("row"))
                    {
                        if (result == null)
                        {
                            result = CreateCollectionWrapper();
                        }
                        if (xmlReader.IsEmptyElement)
                        {
                            xmlReader.Skip();
                            xmlReader.MoveToContent();
                            continue;
                        }
                        xmlReader.ReadStartElement();
                        xmlReader.MoveToContent();

                        var item = this.ElementObjectSerializer.Read(xmlReader);

                        result.Add(item);

                        xmlReader.ReadEndElement();

                        xmlReader.MoveToContent();
                    }
                    else
                    {
                        throw new XmlSerializeException("错误的xml格式文档,集合的元素必须以“row”不根节点。");
                    }
                }
            }
            return(result == null ? null : result.Result);
        }