Esempio n. 1
0
            /// <include file='doc\Queue.uex' path='docs/doc[@for="QueueEnumerator.MoveNext"]/*' />
            public bool MoveNext()
            {
                if (_version != _q._version)
                {
                    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
                }

                if (_index == -2)
                {
                    return(false);
                }

                _index++;

                if (_index == _q._size)
                {
                    _index          = -2;
                    _currentElement = default(T);
                    return(false);
                }

                _currentElement = _q.GetElement(_index);
                return(true);
            }
Esempio n. 2
0
        public void ForEach(Action <T> action)
        {
            if (action == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
            }
            Contract.EndContractBlock();

            int version = _version;

            for (int i = 0; i < _size; i++)
            {
                if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
                {
                    break;
                }
                action(_items[i]);
            }

            if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
            {
                ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
            }
        }
Esempio n. 3
0
            public bool MoveNext()
            {
                if (version != dictionary.version)
                {
                    ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
                }

                // Use unsigned comparison since we set index to dictionary.count+1 when the enumeration ends.
                // dictionary.count+1 could be negative if dictionary.count is Int32.MaxValue
                while ((uint)index < (uint)dictionary.count)
                {
                    if (dictionary.entries[index].hashCode >= 0)
                    {
                        current = new KeyValuePair <TKey, TValue>(dictionary.entries[index].key, dictionary.entries[index].value);
                        index++;
                        return(true);
                    }
                    index++;
                }

                index   = dictionary.count + 1;
                current = new KeyValuePair <TKey, TValue>();
                return(false);
            }