Ejemplo n.º 1
0
 /// <summary>
 /// Create a new variable in the current context.
 /// </summary>
 public void Add(JsVar jsVar)
 {
     if (jsVar.Value == _last)
     {
         Components.Pop();
     }
     if (jsVar.Name == null)
     {
         jsVar.Name = NextName;
     }
     _last = jsVar;
     Components.Add(new JsCommandVar(jsVar));
 }
Ejemplo n.º 2
0
        public bool MoveNext()
        {
            if (_first)
            {
                _first = false;
                return(_node != null);
            }

            while (true)
            {
                // is there the potential to iterate over the current nodes children?
                if (_node.ArraySet)
                {
                    // push current enumerator onto the stack
                    _nodeEnumerators.Add(new Teple <IEnumerator <Node>, bool>(_currentEnumerator, _list));
                    _currentEnumerator = _node.Array.GetEnumerator();
                    if (_currentEnumerator.MoveNext())
                    {
                        _list = true;
                        _node = _currentEnumerator.Current;
                        return(true);
                    }
                }
                if (_node.DictionarySet)
                {
                    // push current enumerator onto the stack
                    _nodeEnumerators.Add(new Teple <IEnumerator <Node>, bool>(_currentEnumerator, _list));
                    _currentEnumerator = _node.Dictionary.Values.GetEnumerator();
                    if (_currentEnumerator.MoveNext())
                    {
                        _list = false;
                        _node = _currentEnumerator.Current;
                        return(true);
                    }
                }

                while (true)
                {
                    // move the current enumerator
                    if (_currentEnumerator.MoveNext())
                    {
                        _node = _currentEnumerator.Current;
                        return(true);
                    }

                    if (_list)
                    {
                        _list = false;
                        if (_node.DictionarySet)
                        {
                            // set the first enumerator as this nodes list
                            _currentEnumerator = _node.Dictionary.Values.GetEnumerator();
                            if (_currentEnumerator.MoveNext())
                            {
                                _node = _currentEnumerator.Current;
                                return(true);
                            }
                        }
                    }

                    // any node enumerators to pop?
                    if (_nodeEnumerators.Count == 0)
                    {
                        return(false);
                    }

                    // pop last enumerator off stack if it exists
                    Teple <IEnumerator <Node>, bool> next = _nodeEnumerators.Pop();
                    _currentEnumerator = next.ArgA;
                    _list = next.ArgB;

                    // move up a node
                    _node = _node.Parent;
                }
            }
        }