示例#1
0
        public XPathNodeIterator GetNodeSet(string xPath)
        {
            ComparisonRequest request = new ComparisonRequest()
            {
                ProductsRequested = new List <Product>()
                {
                    new Product()
                    {
                        Id             = 1,
                        FundsRequested = new List <Fund>()
                        {
                            new Fund()
                            {
                                Id = "dsfjds", Name = "sdjhuuwuw"
                            },
                            new Fund()
                            {
                                Id = "iririr", Name = "vmnvmv"
                            }
                        }
                    },
                    new Product()
                    {
                        Id             = 2,
                        FundsRequested = new List <Fund>()
                        {
                            new Fund()
                            {
                                Id = "ffdjfjfjfj", Name = "ddioeoe"
                            },
                            new Fund()
                            {
                                Id = "diiowiw", Name = "dsjwiw"
                            }
                        }
                    },
                    new Product()
                    {
                        Id             = 3,
                        FundsRequested = new List <Fund>()
                        {
                            new Fund()
                            {
                                Id = "odioiwi", Name = "iioie"
                            },
                            new Fund()
                            {
                                Id = "ieieie", Name = "wuiwosk"
                            }
                        }
                    }
                }
            };

            ObjectXPathNavigator nav = new ObjectXPathNavigator(request);

            XPathNodeIterator i = nav.Select(xPath);

            return(i);
        }
        /// <summary>
        /// When overridden in a derived class, creates a new <see cref="T:System.Xml.XPath.XPathNavigator"></see> positioned at the same node as this <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Xml.XPath.XPathNavigator"></see> positioned at the same node as this <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </returns>
        public override XPathNavigator Clone()
        {
            ObjectXPathNavigator newNav = new ObjectXPathNavigator();

            newNav.m_docElem     = m_docElem;
            newNav.m_currentElem = m_currentElem;
            newNav.m_nodeType    = m_nodeType;
            newNav.m_values      = m_values;
            newNav.m_valueIndex  = m_valueIndex;
            newNav.m_nt          = m_nt;

            return(newNav);
        }
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Xml.XPath.XPathNavigator"></see> is a descendant of the current <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </summary>
        /// <param name="nav">The <see cref="T:System.Xml.XPath.XPathNavigator"></see> to compare to this <see cref="T:System.Xml.XPath.XPathNavigator"></see>.</param>
        /// <returns>
        /// Returns true if the specified <see cref="T:System.Xml.XPath.XPathNavigator"></see> is a descendant of the current <see cref="T:System.Xml.XPath.XPathNavigator"></see>; otherwise, false.
        /// </returns>
        public override bool IsDescendant(XPathNavigator nav)
        {
            if (nav is ObjectXPathNavigator)
            {
                ObjectXPathNavigator otherNav = (ObjectXPathNavigator)nav;

                // if they're in different graphs, they're not the same
                if (this.m_docElem != otherNav.m_docElem)
                {
                    return(false);
                }

                if (m_nodeType == XPathNodeType.Root && otherNav.m_nodeType != XPathNodeType.Root)
                {
                    // its on my root element - its still a descendant
                    return(true);
                }

                // if I'm not on an element, it can't be my descendant
                // (attributes and text don't have descendants)
                if (m_nodeType != XPathNodeType.Element)
                {
                    return(false);
                }

                if (this.m_currentElem == otherNav.m_currentElem)
                {
                    // if its on my attribute or content - its still a descendant
                    return
                        (m_nodeType == XPathNodeType.Element &&
                         otherNav.m_nodeType != XPathNodeType.Element);
                }

                // ok, we need to hunt...
                for (ObjectXPathProxy parent = otherNav.m_currentElem.Parent;
                     parent != null;
                     parent = parent.Parent)
                {
                    if (parent == this.m_currentElem)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// When overridden in a derived class, moves the <see cref="T:System.Xml.XPath.XPathNavigator"></see> to the same position as the specified <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </summary>
        /// <param name="other">The <see cref="T:System.Xml.XPath.XPathNavigator"></see> positioned on the node that you want to move to.</param>
        /// <returns>
        /// Returns true if the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is successful moving to the same position as the specified <see cref="T:System.Xml.XPath.XPathNavigator"></see>; otherwise, false. If false, the position of the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is unchanged.
        /// </returns>
        public override bool MoveTo(XPathNavigator other)
        {
            if (other is ObjectXPathNavigator)
            {
                ObjectXPathNavigator otherNav = (ObjectXPathNavigator)other;

                m_docElem     = otherNav.m_docElem;
                m_currentElem = otherNav.m_currentElem;
                m_nodeType    = otherNav.m_nodeType;
                m_values      = otherNav.m_values;
                m_valueIndex  = otherNav.m_valueIndex;
                m_nt          = otherNav.m_nt;

                return(true);
            }

            return(false);
        }
        public XPathNodeIterator GetNodeSet(string xPath)
        {
            ComparisonRequest request = new ComparisonRequest()
            {
                ProductsRequested = new List<Product>()
                {
                    new Product()
                    {
                        Id = 1,
                        FundsRequested = new List<Fund>()
                        {
                            new Fund() { Id = "dsfjds", Name = "sdjhuuwuw" },
                            new Fund() { Id = "iririr", Name = "vmnvmv" }
                        }
                    },
                    new Product()
                    {
                        Id = 2,
                        FundsRequested = new List<Fund>()
                        {
                            new Fund() { Id = "ffdjfjfjfj", Name = "ddioeoe" },
                            new Fund() { Id = "diiowiw", Name = "dsjwiw" }
                        }
                    },
                    new Product()
                    {
                        Id = 3,
                        FundsRequested = new List<Fund>()
                        {
                            new Fund() { Id = "odioiwi", Name = "iioie" },
                            new Fund() { Id = "ieieie", Name = "wuiwosk" }
                        }
                    }
                }
            };

            ObjectXPathNavigator nav = new ObjectXPathNavigator(request);

            XPathNodeIterator i = nav.Select(xPath);
            return i;
        }
        /// <summary>
        /// When overridden in a derived class, determines whether the current <see cref="T:System.Xml.XPath.XPathNavigator"></see> is at the same position as the specified <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </summary>
        /// <param name="other">The <see cref="T:System.Xml.XPath.XPathNavigator"></see> to compare to this <see cref="T:System.Xml.XPath.XPathNavigator"></see>.</param>
        /// <returns>
        /// Returns true if the two <see cref="T:System.Xml.XPath.XPathNavigator"></see> objects have the same position; otherwise, false.
        /// </returns>
        public override bool IsSamePosition(XPathNavigator other)
        {
            if (other is ObjectXPathNavigator)
            {
                ObjectXPathNavigator otherNav = (ObjectXPathNavigator)other;

                // if they're in different graphs, they're not the same
                if (this.m_docElem != otherNav.m_docElem)
                {
                    return(false);
                }

                // if they're different node types, they can't be the same node!
                if (this.m_nodeType != otherNav.m_nodeType)
                {
                    return(false);
                }

                // if they're different elements, they can't be the same node!
                if (this.m_currentElem != otherNav.m_currentElem)
                {
                    return(false);
                }

                // are they on different attributes?
                if (this.m_nodeType == XPathNodeType.Attribute &&
                    this.m_valueIndex != otherNav.m_valueIndex)
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// When overridden in a derived class, creates a new <see cref="T:System.Xml.XPath.XPathNavigator"></see> positioned at the same node as this <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Xml.XPath.XPathNavigator"></see> positioned at the same node as this <see cref="T:System.Xml.XPath.XPathNavigator"></see>.
        /// </returns>
        public override XPathNavigator Clone()
        {
            ObjectXPathNavigator newNav = new ObjectXPathNavigator();

            newNav.m_docElem = m_docElem;
            newNav.m_currentElem = m_currentElem;
            newNav.m_nodeType = m_nodeType;
            newNav.m_values = m_values;
            newNav.m_valueIndex = m_valueIndex;
            newNav.m_nt = m_nt;

            return newNav;
        }