Skip to content

Commit a873ea0

Browse files
committed
[Empty] add empty generator.
1 parent dd00f41 commit a873ea0

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

src/StructLinq.Tests/EmptyTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace StructLinq.Tests
5+
{
6+
public class EmptyTests
7+
{
8+
[Fact]
9+
public void ShouldBeEmpty()
10+
{
11+
StructEnumerable.Empty<int>()
12+
.ToArray()
13+
.Should()
14+
.BeEmpty();
15+
}
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.CompilerServices;
2+
3+
namespace StructLinq.Empty
4+
{
5+
public struct EmptyEnumerable<T> : IStructEnumerable<T, EmptyEnumerator<T>>
6+
{
7+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8+
public readonly EmptyEnumerator<T> GetEnumerator()
9+
{
10+
return new EmptyEnumerator<T>();
11+
}
12+
}
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace StructLinq.Empty
5+
{
6+
public struct EmptyEnumerator<T> : IStructEnumerator<T>
7+
{
8+
public void Dispose()
9+
{
10+
}
11+
12+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
13+
public bool MoveNext()
14+
{
15+
return false;
16+
}
17+
18+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
public void Reset()
20+
{
21+
}
22+
23+
public T Current
24+
{
25+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
26+
get => throw new NotImplementedException();
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Runtime.CompilerServices;
2+
using StructLinq.Empty;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace StructLinq
6+
{
7+
public static partial class StructEnumerable
8+
{
9+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10+
public static EmptyEnumerable<T> Empty<T>()
11+
{
12+
return new EmptyEnumerable<T>();
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)