Table of Contents

Class CollectionsUtils

Namespace
adas_core.Domain.Utils
Assembly
adas-core.Domain.dll

Provides static utility methods for working with collections.

public static class CollectionsUtils
Inheritance
CollectionsUtils
Inherited Members

Methods

EmptyIfNull<T>(List<T>?)

Returns the provided list as-is when it is not null, or an empty list when it is null, ensuring a non-null result for safe iteration.

public static List<T> EmptyIfNull<T>(List<T>? value)

Parameters

value List<T>

The list to evaluate; may be null.

Returns

List<T>

The original value if it is not null; otherwise, an empty List<T>.

Type Parameters

T

HasElements<T>(List<T>?)

Determines whether the specified list contains at least one element, returning false when the list is null or empty.

public static bool HasElements<T>(List<T>? value)

Parameters

value List<T>

The list to evaluate. May be null.

Returns

bool

true if value is not null and contains one or more elements; otherwise, false.

Type Parameters

T

IfEmptyOrNull(List<string>, List<string>)

Returns the provided default list when the input list is null or empty; otherwise returns the input list unchanged.

public static List<string> IfEmptyOrNull(List<string> list, List<string> defaultList)

Parameters

list List<string>

The list to evaluate for a null or empty state.

defaultList List<string>

The fallback list returned when list is null or empty.

Returns

List<string>

The original list when it contains items; otherwise defaultList.

IsEmptyOrNull<T>(List<T>?)

Determines whether the specified list is null or contains no elements.

public static bool IsEmptyOrNull<T>(List<T>? value)

Parameters

value List<T>

The list to evaluate.

Returns

bool

true if the list is null or empty; otherwise, false.

Type Parameters

T

IsNotEmpty<T>(List<T>)

Determines whether the specified list is neither null nor empty by negating the result of IsEmptyOrNull<T>(List<T>?).

public static bool IsNotEmpty<T>(List<T> value)

Parameters

value List<T>

The list to evaluate.

Returns

bool

true if the list is not null and contains at least one element; otherwise, false.

Type Parameters

T

IsNullOrEmpty<T>(List<T>?)

Determines whether the specified list is null or contains no elements.

public static bool IsNullOrEmpty<T>(this List<T>? value)

Parameters

value List<T>

The list to evaluate.

Returns

bool

true if the list is null or empty; otherwise, false.

Type Parameters

T

NullIfEmpty<T>(List<T>)

Returns null when the specified list is null or contains no elements; otherwise, returns the list as-is.

public static List<T>? NullIfEmpty<T>(List<T> value)

Parameters

value List<T>

The list to evaluate.

Returns

List<T>

The original value when it is not null and not empty; otherwise, null.

Type Parameters

T

ToArray(ICollection, Type)

Converts the specified collection into a strongly typed array of the given element type.

public static Array ToArray(ICollection collection, Type type)

Parameters

collection ICollection

The source collection whose elements are copied into the new array.

type Type

The element Type of the array to create.

Returns

Array

A new Array of the specified type containing the elements copied from the collection.