Beispiel #1
0
        IList <XPathObjectNode> ActivateDictionary()
        {
            // no attributes
            _attributes = _emptyAttributes;

            // collect elements
            var elements = new List <XPathObjectNode>();

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

                var node = new XPathObjectNode(_context, entry.Value, null, this, elements, elements.Count);

                elements.Add(node);

                node.AddSpecialName("key", entry.Key.ToString());
            }

            if (elements.Count == 0)
            {
                _elements.Target = _emptyElements;
            }
            else
            {
                _elements.Target = elements;
            }

            return(elements);
        }
Beispiel #2
0
        XPathObjectNode(XPathObjectContext context, object target, string name, XPathObjectNode parent, IList <XPathObjectNode> siblings, int index)
        {
            _context  = context ?? throw new ArgumentNullException("context");
            _target   = target ?? throw new ArgumentNullException("target");
            _parent   = parent;
            _siblings = siblings;
            _index    = index;

            if (string.IsNullOrEmpty(name))
            {
                if (target is IXmlInfo info)
                {
                    name = info.XmlNodeName();
                }
                else
                {
                    var type = target.GetType();
                    name = target.GetType().Name;
                    if (type.IsGenericType)
                    {
                        name = name.Remove(name.IndexOf('`'));
                    }
                }
            }
            _name = GetAtomicString(name);
        }
Beispiel #3
0
        ///
        public override bool MoveToPrevious()
        {
            if (_type != XPathNodeType.Element)
            {
                return(false);
            }

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

            XPathObjectNode parent = _node.Parent;

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

            var elems = parent.Elements;
            int prev  = _node.Index - 1;

            if (prev < 0)
            {
                return(false);
            }

            MoveNavigator(elems[prev]);
            return(true);
        }
Beispiel #4
0
        ///
        public override bool MoveToNext()
        {
            if (_type != XPathNodeType.Element)
            {
                return(false);
            }

            XPathObjectNode parent = _node.Parent;

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

            var elems = parent.Elements;
            int next  = _node.Index + 1;

            if (next >= elems.Count)
            {
                return(false);
            }

            MoveNavigator(elems[next]);
            return(true);
        }
Beispiel #5
0
 XPathObjectNavigator(XPathObjectNavigator that)
 {
     _context = that._context;
     _root    = that._root;
     _node    = that._node;
     _type    = that._type;
     _index   = that._index;
 }
Beispiel #6
0
        ///
        public override bool MoveTo(XPathNavigator other)
        {
            if (!(other is XPathObjectNavigator that))
            {
                return(false);
            }

            _context = that._context;
            _root    = that._root;
            _node    = that._node;
            _type    = that._type;
            _index   = that._index;

            return(true);
        }
Beispiel #7
0
        ///
        public override bool MoveTo(XPathNavigator other)
        {
            var that = other as XPathObjectNavigator;

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

            _context = that._context;
            _root    = that._root;
            _node    = that._node;
            _type    = that._type;
            _index   = that._index;

            return(true);
        }
Beispiel #8
0
        ///
        internal XPathObjectNavigator(object root, XPathObjectContext context)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            _context = context ?? throw new ArgumentNullException("context");
            _root    = new XPathObjectNode(context, root);

            //???? fails without it
            var type = root.GetType();
            var name = type.FullName;

            if (type.IsGenericType)
            {
                name = name.Remove(name.IndexOf('`'));
            }
            _root.AddSpecialName("type", name);
        }
Beispiel #9
0
        ///
        public override bool MoveToParent()
        {
            if (_type == XPathNodeType.Root)
            {
                return(false);
            }

            if (_type != XPathNodeType.Element)
            {
                _type = XPathNodeType.Element;
                return(true);
            }

            XPathObjectNode parent = _node.Parent;

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

            MoveNavigator(parent);
            return(true);
        }
Beispiel #10
0
 ///
 public override void MoveToRoot()
 {
     _type  = XPathNodeType.Root;
     _node  = null;
     _index = -1;
 }
Beispiel #11
0
 void MoveNavigator(XPathObjectNode that)
 {
     _node  = that;
     _type  = XPathNodeType.Element;
     _index = -1;
 }