Class Extensions
A collection of extension methods for common operations on collections and objects.
Inherited Members
Namespace: Innovt.Core.Collections
Assembly: Innovt.Core.dll
Syntax
public static class Extensions
Remarks
This static class provides extension methods to simplify common operations on collections, such as checking for null or empty, adding items, and merging dictionaries.
Methods
| Edit this page View SourceAddFluent<T>(IList<T>, T)
Initialize the collection if is null, so you don't have to check it
Declaration
public static IList<T> AddFluent<T>(this IList<T> list, T value) where T : class
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | |
T | value |
Returns
Type | Description |
---|---|
IList<T> |
Type Parameters
Name | Description |
---|---|
T |
AddFluent<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue)
Adds a key-value pair to the dictionary and initializes it if it is null.
Declaration
public static Dictionary<TKey, TValue> AddFluent<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<TKey, TValue> | dictionary | The Dictionary<TKey, TValue> to add to. |
TKey | key | The key to add to the dictionary. |
TValue | value | The value to add to the dictionary. |
Returns
Type | Description |
---|---|
Dictionary<TKey, TValue> |
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary. |
TValue | The type of values in the dictionary. |
HasItems<T>(ICollection<T>)
Returns if the collection has more items
Declaration
public static bool HasItems<T>(this ICollection<T> collection)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T |
IsNotNullOrEmpty<T>(ICollection<T>)
Checks if an ICollection<T> is not null and not empty.
Declaration
public static bool IsNotNullOrEmpty<T>(this ICollection<T> collection)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | The ICollection<T> to check. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in the collection. |
IsNotNullOrEmpty<T>(IEnumerable<T>)
Checks if an IEnumerable<T> is not null and not empty.
Declaration
public static bool IsNotNullOrEmpty<T>(this IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumerable | The IEnumerable<T> to check. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in the enumerable. |
IsNullOrEmpty<T>(ICollection<T>)
Checks if an ICollection<T> is null or empty.
Declaration
public static bool IsNullOrEmpty<T>(this ICollection<T> collection)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | collection | The ICollection<T> to check. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in the collection. |
IsNullOrEmpty<T>(IEnumerable<T>)
Checks if an IEnumerable<T> is null or empty.
Declaration
public static bool IsNullOrEmpty<T>(this IEnumerable<T> enumerable)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | enumerable | The IEnumerable<T> to check. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in the enumerable. |
IsNullOrEmpty<T>(IList<T>)
Checks if an IList<T> is null or empty.
Declaration
public static bool IsNullOrEmpty<T>(this IList<T> list)
Parameters
Type | Name | Description |
---|---|---|
IList<T> | list | The IList<T> to check. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The type of elements in the list. |
MapToPagedCollection<T, T2>(IPagedCollection<T>)
Using a simple mapper to map an page collection of objects to another page collection of objects
Declaration
public static PagedCollection<T2> MapToPagedCollection<T, T2>(this IPagedCollection<T> pageCollection) where T : class where T2 : class
Parameters
Type | Name | Description |
---|---|---|
IPagedCollection<T> | pageCollection |
Returns
Type | Description |
---|---|
PagedCollection<T2> |
Type Parameters
Name | Description |
---|---|
T | |
T2 |
Merge<TKey, TValue>(Dictionary<TKey, TValue>, Dictionary<TKey, TValue>)
Merges two dictionaries, adding values from the second dictionary to the first.
Declaration
public static Dictionary<TKey, TValue> Merge<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Dictionary<TKey, TValue> dictionarySecond)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<TKey, TValue> | dictionary | The target Dictionary<TKey, TValue> to merge into. |
Dictionary<TKey, TValue> | dictionarySecond | The source dictionary to merge from. |
Returns
Type | Description |
---|---|
Dictionary<TKey, TValue> | The updated dictionary after merging. |
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionaries. |
TValue | The type of values in the dictionaries. |