=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===
This commit is contained in:
@@ -5,6 +5,7 @@ namespace adas_core.Domain.Utils;
|
||||
/// <summary>
|
||||
/// Provides static utility methods for working with collections.
|
||||
/// </summary>
|
||||
/// <!-- aidoc:v1 sig=50818c2 -->
|
||||
public static class CollectionsUtils
|
||||
{
|
||||
/// <summary>
|
||||
@@ -12,6 +13,7 @@ public static class CollectionsUtils
|
||||
/// </summary>
|
||||
/// <param name="value">The list to evaluate.</param>
|
||||
/// <returns><see langword="true"/> if the list is null or empty; otherwise, <see langword="false"/>.</returns>
|
||||
/// <!-- aidoc:v1 sig=dfb5373 body=1cd2a38 -->
|
||||
public static bool IsNullOrEmpty<T>(this List<T>? value)
|
||||
{
|
||||
return value == null || !value.Any();
|
||||
@@ -22,6 +24,7 @@ public static class CollectionsUtils
|
||||
/// </summary>
|
||||
/// <param name="value">The list to evaluate.</param>
|
||||
/// <returns><see langword="true"/> if the list is <see langword="null"/> or empty; otherwise, <see langword="false"/>.</returns>
|
||||
/// <!-- aidoc:v1 sig=5038079 body=1cd2a38 -->
|
||||
public static bool IsEmptyOrNull<T>(List<T>? value)
|
||||
{
|
||||
return value == null || !value.Any();
|
||||
@@ -32,6 +35,7 @@ public static class CollectionsUtils
|
||||
/// </summary>
|
||||
/// <param name="value">The list to evaluate. May be <c>null</c>.</param>
|
||||
/// <returns><c>true</c> if <paramref name="value"/> is not <c>null</c> and contains one or more elements; otherwise, <c>false</c>.</returns>
|
||||
/// <!-- aidoc:v1 sig=2c3b8ff body=0269891 -->
|
||||
public static bool HasElements<T>(List<T>? value)
|
||||
{
|
||||
return value != null && value.Any();
|
||||
@@ -42,6 +46,7 @@ public static class CollectionsUtils
|
||||
/// </summary>
|
||||
/// <param name="value">The list to evaluate.</param>
|
||||
/// <returns><see langword="true"/> if the list is not null and contains at least one element; otherwise, <see langword="false"/>.</returns>
|
||||
/// <!-- aidoc:v1 sig=61945f3 body=2b7a733 -->
|
||||
public static bool IsNotEmpty<T>(List<T> value)
|
||||
{
|
||||
return !IsEmptyOrNull(value);
|
||||
@@ -52,6 +57,7 @@ public static class CollectionsUtils
|
||||
/// </summary>
|
||||
/// <param name="value">The list to evaluate; may be <see langword="null"/>.</param>
|
||||
/// <returns>The original <paramref name="value"/> if it is not null; otherwise, an empty <see cref="List{T}"/>.</returns>
|
||||
/// <!-- aidoc:v1 sig=4b33799 body=5556777 -->
|
||||
public static List<T> EmptyIfNull<T>(List<T>? value)
|
||||
{
|
||||
return value ?? [];
|
||||
@@ -62,6 +68,7 @@ public static class CollectionsUtils
|
||||
/// </summary>
|
||||
/// <param name="value">The list to evaluate.</param>
|
||||
/// <returns>The original <paramref name="value"/> when it is not null and not empty; otherwise, <c>null</c>.</returns>
|
||||
/// <!-- aidoc:v1 sig=a05f7fc body=74812a2 -->
|
||||
public static List<T>? NullIfEmpty<T>(List<T> value)
|
||||
{
|
||||
return IsEmptyOrNull(value) ? null : value;
|
||||
@@ -73,6 +80,7 @@ public static class CollectionsUtils
|
||||
/// <param name="collection">The source collection whose elements are copied into the new array.</param>
|
||||
/// <param name="type">The element <see cref="Type"/> of the array to create.</param>
|
||||
/// <returns>A new <see cref="Array"/> of the specified type containing the elements copied from the collection.</returns>
|
||||
/// <!-- aidoc:v1 sig=98732cd body=d08ef3a -->
|
||||
public static Array ToArray(ICollection collection, Type type)
|
||||
{
|
||||
var result = Array.CreateInstance(type, collection.Count);
|
||||
@@ -86,6 +94,7 @@ public static class CollectionsUtils
|
||||
/// <param name="list">The list to evaluate for a null or empty state.</param>
|
||||
/// <param name="defaultList">The fallback list returned when <paramref name="list"/> is null or empty.</param>
|
||||
/// <returns>The original <paramref name="list"/> when it contains items; otherwise <paramref name="defaultList"/>.</returns>
|
||||
/// <!-- aidoc:v1 sig=c865748 body=df53ea7 -->
|
||||
public static List<string> IfEmptyOrNull(List<string> list, List<string> defaultList)
|
||||
{
|
||||
return IsEmptyOrNull(list) ? defaultList : list;
|
||||
|
||||
Reference in New Issue
Block a user