internal SharpObjectList(SharpObject parent, string name, SharpRowCursor source, SharpNode node = null, bool useCache = false)
 {
     _parent   = parent;
     _name     = name;
     _source   = source;
     _useCache = useCache;
     _node     = node;
 }
        public IEnumerator <SharpObject> GetEnumerator()
        {
            bool expandSource = false;

            lock (_sync)
            {
                expandSource = !_isExpanded && _source != null;
            }

            if (_useCache)
            {
                int length = _items.Count;
                for (int i = 0; i < length; i++)
                {
                    if (_items[i] != null)
                    {
                        yield return(_items[i]);
                    }
                }
            }

            if (expandSource)
            {
                List <SharpObject> newItems = new List <SharpObject>();

                // Copy the cursor so this can be called by multiple threads
                var cursor = new SharpRowCursor(_source);
                cursor.Reset();

                while (cursor.MoveNext())
                {
                    if (_node != null && cursor.Current.Node != _node)
                    {
                        break;
                    }

                    var obj = new SharpObject(cursor.Current);
                    if (_useCache)
                    {
                        newItems.Add(obj);
                    }

                    yield return(obj);
                }

                lock (_sync)
                {
                    if (!_isExpanded && _useCache)
                    {
                        _items.AddRange(newItems);
                        _isExpanded = true;
                    }
                }
            }
        }
 public SharpRowCursor(SharpRowCursor source)
 {
     _top     = source._top;
     _current = source._current;
     _done    = source._done;
 }