-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathArrayExtensions.cs
More file actions
42 lines (38 loc) · 1.71 KB
/
ArrayExtensions.cs
File metadata and controls
42 lines (38 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace System;
public static class ArrayExtensions
{
/// <summary>
/// A fluid alternative to <see cref="Array.Exists{T}(T[], Predicate{T})"/>.
/// </summary>
/// <remarks>
/// <para>
/// According to <see href="https://rules.sonarsource.com/csharp/RSPEC-6605">SonarSource's rule RSPEC-6605</see>
/// it's better to use this instead of the general `Any()` extension method.
/// </para>
/// </remarks>
public static bool Exists<T>(this T[] array, Predicate<T> match) => Array.Exists(array, match);
/// <summary>
/// A fluid alternative to <see cref="Array.Find{T}(T[], Predicate{T})"/>.
/// </summary>
/// <remarks>
/// <para>
/// According to <see href="https://rules.sonarsource.com/csharp/RSPEC-6602">SonarSource's rule RSPEC-6602</see>
/// it's better to use this instead of the general `FirstOrDefault()` extension method.
/// </para>
/// </remarks>
public static T? Find<T>(this T[] array, Predicate<T> match) => Array.Find(array, match);
/// <summary>
/// A fluid alternative to <see cref="Array.FindAll{T}(T[], Predicate{T})"/>.
/// </summary>
public static T[] FindAll<T>(this T[] array, Predicate<T> match) => Array.FindAll(array, match);
/// <summary>
/// A fluid alternative to <see cref="Array.FindIndex{T}(T[], Predicate{T})"/>.
/// </summary>
/// <remarks>
/// <para>
/// According to <see href="https://rules.sonarsource.com/csharp/RSPEC-6603">SonarSource's rule RSPEC-6603</see>
/// it's better to use this instead of the general `All()` extension method.
/// </para>
/// </remarks>
public static bool TrueForAll<T>(this T[] array, Predicate<T> match) => Array.TrueForAll(array, match);
}