Class CollectionsUtils
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
Returns
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
valueList<T>The list to evaluate. May be
null.
Returns
- bool
trueifvalueis notnulland 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
listList<string>The list to evaluate for a null or empty state.
defaultListList<string>The fallback list returned when
listis null or empty.
Returns
IsEmptyOrNull<T>(List<T>?)
Determines whether the specified list is null or contains no elements.
public static bool IsEmptyOrNull<T>(List<T>? value)
Parameters
valueList<T>The list to evaluate.
Returns
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
valueList<T>The list to evaluate.
Returns
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
valueList<T>The list to evaluate.
Returns
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
valueList<T>The list to evaluate.
Returns
- List<T>
The original
valuewhen 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
collectionICollectionThe source collection whose elements are copied into the new array.
typeTypeThe element Type of the array to create.