Skip to content

Commit 57932a1

Browse files
author
Smurf-IV
committed
Initial commit for jackmott#24: [Enhancement] DefaultIfEmptyF should be implemented
- Add Start File
1 parent ac38801 commit 57932a1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

LinqFaster/DefaultIfEmpty.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Runtime.CompilerServices;
2+
// ReSharper disable ForCanBeConvertedToForeach
3+
// ReSharper disable UnusedMember.Global
4+
5+
namespace JM.LinqFaster
6+
{
7+
public static partial class LinqFaster
8+
{
9+
// -------------------------- Arrays --------------------------------------------
10+
11+
/// <summary>
12+
/// Returns an array (For speed) with a single value set to default{T}
13+
/// </summary>
14+
/// <typeparam name="T"></typeparam>
15+
/// <param name="source"></param>
16+
/// <returns>source or new array{1}</returns>
17+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
18+
public static T[] DefaultIfEmptyF<T>(this T[] source)
19+
{
20+
if ((source == null)
21+
|| (source.Length == 0)
22+
)
23+
{
24+
return new T[] { default(T) };
25+
}
26+
return source;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)