/// <summary>
 /// copy constructor.
 /// </summary>
 /// <param name="other">navigator to be copied</param>
 public XPathObjectNavigator(XPathObjectNavigator other)
 {
     _context = other._context;
     _state   = other._state;
     _root    = other._root;
     _lang    = other._lang;
 }
		/// <summary>
		/// Create a new navigator for the object graph
		/// starting at node. The node's name is nodeName.
		/// </summary>
		/// <param name="node">root</param>
		/// <param name="nodeName">root's name</param>
		public XPathObjectNavigator(object node, string nodeName)
		{
			_context = new ObjectNavigationContext();
			_context.NameTable.Add(string.Empty);			
			_root = new ObjectNavigatorStateRoot(_context, node, nodeName);
			_state = _root.MoveToFirstChild();
			_lang = _context.NameTable.Add("en-US");
		}
 /// <summary>
 /// Create a new navigator for the object graph
 /// starting at node. The node's name is nodeName.
 /// </summary>
 /// <param name="node">root</param>
 /// <param name="nodeName">root's name</param>
 public XPathObjectNavigator(object node, string nodeName)
 {
     _context = new ObjectNavigationContext();
     _context.NameTable.Add(string.Empty);
     _root  = new ObjectNavigatorStateRoot(_context, node, nodeName);
     _state = _root.MoveToFirstChild();
     _lang  = _context.NameTable.Add("en-US");
 }
		public ObjectNavigatorState(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name)
		{			
			_parent = parent;
			_context = context;
			_node = node;
			_name = _context.NameTable.Add(name);
			_index = 0;
		}
		internal ObjectNavigatorStateRoot(ObjectNavigationContext context, object node, string nodeName) : base(context, null, node, "#document")
		{
			if (null == nodeName)
			{
				nodeName = _node.GetType().Name;
			}
			
			_child = CreateElementState(context, this, node, nodeName);
		}
        /// <summary>
        /// See <see cref="System.Xml.XPath.XPathNavigator.MoveTo" /> for details.
        /// </summary>
        public override bool MoveTo(System.Xml.XPath.XPathNavigator other)
        {
            Trace("MoveTo");
            XPathObjectNavigator navigator = other as XPathObjectNavigator;

            if (null == other)
            {
                return(false);
            }
            _state   = navigator._state;
            _root    = navigator._root;
            _context = navigator._context;
            return(true);
        }
		internal static ObjectNavigatorState CreateElementState(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name)
		{
			if (node is IDictionary)
			{
				return new ObjectNavigatorStateDictionary(context, parent, node, name);
			}
			else if (node is IList)
			{
				return new ObjectNavigatorStateList(context, parent, node, name);
			}
			else
			{
				return new ObjectNavigatorStateItem(context, parent, node, name);
			}
		}
		internal ObjectNavigatorStateItem(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) :
			base(context, parent, node, name)
		{
		}
		internal ObjectNavigatorStateDictionary(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) :
			base(context, parent, node, name)
		{
			_dictionary = (IDictionary)node;
			_children = new ArrayList(_dictionary.Keys);
		}
		internal ObjectNavigatorStateList(ObjectNavigationContext context, ObjectNavigatorState parent, object node, string name) :
			base(context, parent, node, name)
		{
			_children = (IList)node;			
		}
		/// <summary>
		/// copy constructor.
		/// </summary>
		/// <param name="other">navigator to be copied</param>
		public XPathObjectNavigator(XPathObjectNavigator other)
		{
			_context = other._context;
			_state = other._state;
			_root = other._root;
			_lang = other._lang;
		}
		/// <summary>
		/// See <see cref="System.Xml.XPath.XPathNavigator.MoveTo" /> for details.
		/// </summary>
		public override bool MoveTo(System.Xml.XPath.XPathNavigator other)
		{
			Trace("MoveTo");
			XPathObjectNavigator navigator = other as XPathObjectNavigator;
			if (null == other)
			{
				return false;
			}
			_state = navigator._state;
			_root = navigator._root;
			_context = navigator._context;
			return true;
		}