Skip to content

Commit 412684a

Browse files
authored
Add collection related interfaces and classes (#253)
***NO_CI***
1 parent 03e6ddb commit 412684a

File tree

10 files changed

+414
-261
lines changed

10 files changed

+414
-261
lines changed

nanoFramework.CoreLibrary/CoreLibrary.nfproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
3939
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
4040
<RestoreLockedMode Condition="'$(TF_BUILD)' == 'True' or '$(ContinuousIntegrationBuild)' == 'True'">true</RestoreLockedMode>
41-
<LangVersion>default</LangVersion>
41+
<LangVersion>13.0</LangVersion>
4242
</PropertyGroup>
4343
<PropertyGroup>
4444
<SignAssembly>true</SignAssembly>
@@ -66,10 +66,12 @@
6666
<Compile Include="System\AppDomainUnloadedException.cs" />
6767
<Compile Include="System\ApplicationException.cs" />
6868
<Compile Include="System\ArgumentException.cs" />
69+
<Compile Include="System\Array.Enumerators.cs" />
6970
<Compile Include="System\ArrayTypeMismatchException.cs" />
70-
<Compile Include="System\Collections\Generic\ComparerHelpers.cs" />
7171
<Compile Include="System\Collections\Generic\Comparer.cs" />
72+
<Compile Include="System\Collections\Generic\IEnumerable.cs" />
7273
<Compile Include="System\Collections\Generic\IComparer.cs" />
74+
<Compile Include="System\Collections\Generic\IEnumerator.cs" />
7375
<Compile Include="System\Diagnostics\StackTraceHiddenAttribute.cs" />
7476
<Compile Include="System\Nullable.cs" />
7577
<Compile Include="System\Runtime\InteropServices\InAttribute .cs" />
@@ -260,4 +262,4 @@
260262
<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')" />
261263
<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')" />
262264
<Import Project="..\packages\Nerdbank.GitVersioning.3.7.115\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.7.115\build\Nerdbank.GitVersioning.targets')" />
263-
</Project>
265+
</Project>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Reflection;
8+
using System.Runtime.CompilerServices;
9+
10+
#nullable enable
11+
12+
namespace System
13+
{
14+
internal abstract class SZGenericArrayEnumeratorBase : IDisposable
15+
{
16+
protected int _index;
17+
protected readonly int _endIndex;
18+
19+
protected SZGenericArrayEnumeratorBase(int endIndex)
20+
{
21+
_index = -1;
22+
_endIndex = endIndex;
23+
}
24+
25+
public bool MoveNext()
26+
{
27+
int index = _index + 1;
28+
29+
if ((uint)index < (uint)_endIndex)
30+
{
31+
_index = index;
32+
33+
return true;
34+
}
35+
36+
_index = _endIndex;
37+
38+
return false;
39+
}
40+
41+
public void Reset() => _index = -1;
42+
43+
public void Dispose()
44+
{
45+
}
46+
}
47+
48+
internal sealed class SZGenericArrayEnumerator<T> : SZGenericArrayEnumeratorBase, IEnumerator<T>
49+
{
50+
private readonly T[]? _array;
51+
52+
/// <summary>Provides an empty enumerator singleton.</summary>
53+
/// <remarks>
54+
/// If the consumer is using SZGenericArrayEnumerator elsewhere or is otherwise likely
55+
/// to be using T[] elsewhere, this singleton should be used. Otherwise, GenericEmptyEnumerator's
56+
/// singleton should be used instead, as it doesn't reference T[] in order to reduce footprint.
57+
/// </remarks>
58+
internal static readonly SZGenericArrayEnumerator<T> Empty = new SZGenericArrayEnumerator<T>(null, 0);
59+
60+
internal SZGenericArrayEnumerator(T[]? array, int endIndex)
61+
: base(endIndex)
62+
{
63+
Debug.Assert(array == null || endIndex == array.Length);
64+
_array = array;
65+
}
66+
67+
public T Current
68+
{
69+
get
70+
{
71+
if ((uint)_index >= (uint)_endIndex)
72+
{
73+
throw new InvalidOperationException();
74+
}
75+
76+
return _array![_index];
77+
}
78+
}
79+
80+
object? IEnumerator.Current => Current;
81+
}
82+
83+
internal abstract class GenericEmptyEnumeratorBase : IDisposable, IEnumerator
84+
{
85+
#pragma warning disable CA1822 // https://github.com/dotnet/roslyn-analyzers/issues/5911
86+
public bool MoveNext() => false;
87+
88+
public object Current
89+
{
90+
get
91+
{
92+
return default;
93+
}
94+
}
95+
96+
public void Reset() { }
97+
98+
public void Dispose() { }
99+
#pragma warning restore CA1822
100+
}
101+
}

0 commit comments

Comments
 (0)