Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions nanoFramework.CoreLibrary/CoreLibrary.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RestoreLockedMode Condition="'$(TF_BUILD)' == 'True' or '$(ContinuousIntegrationBuild)' == 'True'">true</RestoreLockedMode>
<LangVersion>default</LangVersion>
<LangVersion>13.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down Expand Up @@ -66,10 +66,12 @@
<Compile Include="System\AppDomainUnloadedException.cs" />
<Compile Include="System\ApplicationException.cs" />
<Compile Include="System\ArgumentException.cs" />
<Compile Include="System\Array.Enumerators.cs" />
<Compile Include="System\ArrayTypeMismatchException.cs" />
<Compile Include="System\Collections\Generic\ComparerHelpers.cs" />
<Compile Include="System\Collections\Generic\Comparer.cs" />
<Compile Include="System\Collections\Generic\IEnumerable.cs" />
<Compile Include="System\Collections\Generic\IComparer.cs" />
<Compile Include="System\Collections\Generic\IEnumerator.cs" />
<Compile Include="System\Diagnostics\StackTraceHiddenAttribute.cs" />
<Compile Include="System\Nullable.cs" />
<Compile Include="System\Runtime\InteropServices\InAttribute .cs" />
Expand Down Expand Up @@ -260,4 +262,4 @@
<Import Project="..\packages\Microsoft.SourceLink.Common.1.1.1\build\Microsoft.SourceLink.Common.targets" Condition="Exists('..\packages\Microsoft.SourceLink.Common.1.1.1\build\Microsoft.SourceLink.Common.targets')" />
<Import Project="..\packages\Microsoft.SourceLink.GitHub.1.1.1\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('..\packages\Microsoft.SourceLink.GitHub.1.1.1\build\Microsoft.SourceLink.GitHub.targets')" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.7.115\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.7.115\build\Nerdbank.GitVersioning.targets')" />
</Project>
</Project>
101 changes: 101 additions & 0 deletions nanoFramework.CoreLibrary/System/Array.Enumerators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;

#nullable enable

namespace System
{
internal abstract class SZGenericArrayEnumeratorBase : IDisposable
{
protected int _index;
protected readonly int _endIndex;

protected SZGenericArrayEnumeratorBase(int endIndex)
{
_index = -1;
_endIndex = endIndex;
}

public bool MoveNext()
{
int index = _index + 1;

if ((uint)index < (uint)_endIndex)
{
_index = index;

return true;
}

_index = _endIndex;

return false;
}

public void Reset() => _index = -1;

public void Dispose()
{
}
}

internal sealed class SZGenericArrayEnumerator<T> : SZGenericArrayEnumeratorBase, IEnumerator<T>
{
private readonly T[]? _array;

/// <summary>Provides an empty enumerator singleton.</summary>
/// <remarks>
/// If the consumer is using SZGenericArrayEnumerator elsewhere or is otherwise likely
/// to be using T[] elsewhere, this singleton should be used. Otherwise, GenericEmptyEnumerator's
/// singleton should be used instead, as it doesn't reference T[] in order to reduce footprint.
/// </remarks>
internal static readonly SZGenericArrayEnumerator<T> Empty = new SZGenericArrayEnumerator<T>(null, 0);

internal SZGenericArrayEnumerator(T[]? array, int endIndex)
: base(endIndex)
{
Debug.Assert(array == null || endIndex == array.Length);
_array = array;
}

public T Current
{
get
{
if ((uint)_index >= (uint)_endIndex)
{
throw new InvalidOperationException();
}

return _array![_index];
}
}

object? IEnumerator.Current => Current;
}

internal abstract class GenericEmptyEnumeratorBase : IDisposable, IEnumerator
{
#pragma warning disable CA1822 // https://github.com/dotnet/roslyn-analyzers/issues/5911
public bool MoveNext() => false;

public object Current
{
get
{
return default;
}
}

public void Reset() { }

public void Dispose() { }
#pragma warning restore CA1822
}
}
Loading