File: ArrayBuilder.Enumerator.cs
Web Access
Project: ..\..\..\src\Microsoft.CodeAnalysis.NetAnalyzers\tests\Test.Utilities\Test.Utilities.csproj (Test.Utilities)
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the MIT license.  See License.txt in the project root for license information.
 
using System.Collections.Generic;
 
#pragma warning disable CA1710 // Rename Microsoft.CodeAnalysis.ArrayBuilder<T> to end in 'Collection'.
 
namespace Analyzer.Utilities.PooledObjects
{
    internal partial class ArrayBuilder<T>
    {
        /// <summary>
        /// struct enumerator used in foreach.
        /// </summary>
        internal struct Enumerator : IEnumerator<T>
        {
            private readonly ArrayBuilder<T> _builder;
            private int _index;
 
            public Enumerator(ArrayBuilder<T> builder)
            {
                _builder = builder;
                _index = -1;
            }
 
            public readonly T Current => _builder[_index];
 
            public bool MoveNext()
            {
                _index++;
                return _index < _builder.Count;
            }
 
            public readonly void Dispose()
            {
            }
 
            readonly object? System.Collections.IEnumerator.Current => this.Current;
 
            public void Reset()
            {
                _index = -1;
            }
        }
    }
}