/// <summary>
 /// Moves the navigator.
 /// </summary>
 /// <param name="nav">The nav.</param>
 private void MoveNavigator(ObjectXPathProxy nav)
 {
     m_nodeType    = XPathNodeType.Element;
     m_currentElem = nav;
     m_values      = nav.Elements;
     m_valueIndex  = -1;
 }
        /// <summary>
        /// Activates the dictionary.
        /// </summary>
        private void ActivateDictionary()
        {
            List <ObjectXPathProxy> elements = new List <ObjectXPathProxy>();

            m_elemDict = new Hashtable();

            foreach (DictionaryEntry entry in (IDictionary)binding)
            {
                if (entry.Value == null)
                {
                    continue;
                }

                ObjectXPathProxy item =
                    new ObjectXPathProxy(entry.Value, entry.Value.GetType().Name, this, m_nt);

                elements.Add(item);

                item.AddSpecialName("key", entry.Key.ToString());

                m_elemDict[entry.Key.ToString()] = item;
            }

            m_elements = (elements.Count != 0) ? elements : null;
        }
        /// <summary>
        /// When overridden in a derived class, moves the <see cref="T:System.Xml.XPath.XPathNavigator"></see> to the next sibling node of the current node.
        /// </summary>
        /// <returns>
        /// true if the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is successful moving to the next sibling node; otherwise, false if there are no more siblings or if the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is currently positioned on an attribute node. If false, the position of the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is unchanged.
        /// </returns>
        public override bool MoveToNext()
        {
            if (m_nodeType != XPathNodeType.Element)
            {
                return(false);
            }

            ObjectXPathProxy parent = m_currentElem.Parent;

            if (parent == null)
            {
                return(false);
            }

            bool foundIt = false;

            foreach (ObjectXPathProxy sib in parent.Elements)
            {
                if (foundIt)
                {
                    MoveNavigator(sib);

                    return(true);
                }

                if (m_currentElem == sib)
                {
                    foundIt = true;
                }
            }

            return(false);
        }
 /// <summary>
 /// Moves the <see cref="T:System.Xml.XPath.XPathNavigator"></see> to the root node that the current node belongs to.
 /// </summary>
 public override void MoveToRoot()
 {
     m_nodeType    = XPathNodeType.Root;
     m_currentElem = null;
     m_values      = null;
     m_valueIndex  = -1;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectXPathProxy"/> class.
 /// </summary>
 /// <param name="bindingObj">The binding obj.</param>
 /// <param name="name">The name.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="nt">The nt.</param>
 private ObjectXPathProxy(
     object bindingObj, string name, ObjectXPathProxy parent, XmlNameTable nt)
 {
     binding  = bindingObj;
     m_parent = parent;
     m_nt     = nt;
     m_name   = GetAtomicString(name);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectXPathProxy"/> class.
 /// </summary>
 /// <param name="bindingObj">The binding obj.</param>
 /// <param name="name">The name.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="nt">The nt.</param>
 private ObjectXPathProxy(
     object bindingObj, string name, ObjectXPathProxy parent, XmlNameTable nt)
 {
     binding = bindingObj;
     m_parent = parent;
     m_nt = nt;
     m_name = GetAtomicString(name);
 }
        /// <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);
        }
        /// <summary>
        /// When overridden in a derived class, moves the <see cref="T:System.Xml.XPath.XPathNavigator"></see> to the previous sibling node of the current node.
        /// </summary>
        /// <returns>
        /// Returns true if the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is successful moving to the previous sibling node; otherwise, false if there is no previous sibling node or if the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is currently positioned on an attribute node. If false, the position of the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is unchanged.
        /// </returns>
        public override bool MoveToPrevious()
        {
            if (m_nodeType != XPathNodeType.Element)
            {
                return(false);
            }

            if (m_nodeType != XPathNodeType.Element)
            {
                return(false);
            }

            ObjectXPathProxy parent = m_currentElem.Parent;

            if (parent == null)
            {
                return(false);
            }

            ObjectXPathProxy previous = null;

            foreach (ObjectXPathProxy sib in parent.Elements)
            {
                if (sib == m_currentElem)
                {
                    if (previous == null)
                    {
                        break;
                    }

                    MoveNavigator(previous);

                    return(true);
                }

                previous = sib;
            }

            return(false);
        }
        /// <summary>
        /// When overridden in a derived class, moves the <see cref="T:System.Xml.XPath.XPathNavigator"></see> to the parent node of the current node.
        /// </summary>
        /// <returns>
        /// Returns true if the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is successful moving to the parent node of the current node; otherwise, false. If false, the position of the <see cref="T:System.Xml.XPath.XPathNavigator"></see> is unchanged.
        /// </returns>
        public override bool MoveToParent()
        {
            if (m_nodeType == XPathNodeType.Root)
            {
                return(false);
            }

            if (m_nodeType != XPathNodeType.Element)
            {
                m_nodeType = XPathNodeType.Element;

                return(true);
            }

            ObjectXPathProxy parent = m_currentElem.Parent;

            if (parent == null)
            {
                return(false);
            }

            MoveNavigator(parent);
            return(true);
        }
Пример #11
0
        /// <summary>
        /// Activates the dictionary.
        /// </summary>
        private void ActivateDictionary()
        {
            List<ObjectXPathProxy> elements = new List<ObjectXPathProxy>();

            m_elemDict = new Hashtable();

            foreach (DictionaryEntry entry in (IDictionary)binding)
            {
                if (entry.Value == null)
                {
                    continue;
                }

                ObjectXPathProxy item =
                    new ObjectXPathProxy(entry.Value, entry.Value.GetType().Name, this, m_nt);

                elements.Add(item);

                item.AddSpecialName("key", entry.Key.ToString());

                m_elemDict[entry.Key.ToString()] = item;
            }

            m_elements = (elements.Count != 0) ? elements : null;
        }
 /// <summary>
 /// Moves the navigator.
 /// </summary>
 /// <param name="nav">The nav.</param>
 private void MoveNavigator(ObjectXPathProxy nav)
 {
     m_nodeType = XPathNodeType.Element;
     m_currentElem = nav;
     m_values = nav.Elements;
     m_valueIndex = -1;
 }
 /// <summary>
 /// Moves the <see cref="T:System.Xml.XPath.XPathNavigator"></see> to the root node that the current node belongs to.
 /// </summary>
 public override void MoveToRoot()
 {
     m_nodeType = XPathNodeType.Root;
     m_currentElem = null;
     m_values = null;
     m_valueIndex = -1;
 }
        /// <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;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectXPathNavigator"/> class.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public ObjectXPathNavigator(object obj)
        {
            m_docElem = new ObjectXPathProxy(obj, m_nt);

            m_docElem.AddSpecialName("type", obj.GetType().FullName);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectXPathNavigator"/> class.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public ObjectXPathNavigator(object obj)
        {
            m_docElem = new ObjectXPathProxy(obj, m_nt);

            m_docElem.AddSpecialName("type", obj.GetType().FullName);
        }