File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments