NanoByte.Common  2.9.0
NanoByte.Common.Collections.ListExtensions Class Reference

Provides extension methods for List<T>s. More...

Static Public Member Functions

static void AddRange< TList, TElements > (this IList< TList > list, [InstantHandle] IEnumerable< TElements > elements)
 Adds multiple elements to the list. More...
 
static void RemoveLast< T > (this List< T > list, int number=1)
 Removes the last n elements from the list. More...
 
static bool AddOrReplace< T, TKey > (this List< T > list, T element, [InstantHandle] Func< T, TKey > keySelector)
 Adds or replaces an element in a list using a key selector for comparison. More...
 
static bool AddOrReplace< T > (this List< T > list, T element)
 Adds or replaces an element in a list. More...
 
static IList< T > GetAddedElements< T > (this IList< T >? newList, IList< T >? oldList, IComparer< T > comparer)
 Assumes two sorted lists. Determines which elements are present in newList but not in oldList . More...
 
static IList< T > GetAddedElements< T > (this IList< T >? newList, IList< T >? oldList)
 Assumes two sorted lists. Determines which elements are present in newList but not in oldList . More...
 

Detailed Description

Provides extension methods for List<T>s.

Member Function Documentation

◆ AddOrReplace< T >()

static bool NanoByte.Common.Collections.ListExtensions.AddOrReplace< T > ( this List< T >  list,
element 
)
inlinestatic

Adds or replaces an element in a list.

Parameters
listThe list to update.
elementThe element to add or update.
Returns

◆ AddOrReplace< T, TKey >()

static bool NanoByte.Common.Collections.ListExtensions.AddOrReplace< T, TKey > ( this List< T >  list,
element,
[InstantHandle] Func< T, TKey >  keySelector 
)
inlinestatic

Adds or replaces an element in a list using a key selector for comparison.

Parameters
listThe list to update.
elementThe element to add or update.
keySelectorUsed to map elements to keys for comparison
Returns

◆ AddRange< TList, TElements >()

static void NanoByte.Common.Collections.ListExtensions.AddRange< TList, TElements > ( this IList< TList >  list,
[InstantHandle] IEnumerable< TElements >  elements 
)
inlinestatic

Adds multiple elements to the list.

This is a covariant wrapper for List<T>.AddRange.

Type Constraints
TElements :TList 

◆ GetAddedElements< T >() [1/2]

static IList<T> NanoByte.Common.Collections.ListExtensions.GetAddedElements< T > ( this IList< T >?  newList,
IList< T >?  oldList 
)
static

Assumes two sorted lists. Determines which elements are present in newList but not in oldList .

Parameters
newListThe new list of elements; can be null (will be treated as an empty list).
oldListThe original list of elements; can be null (will be treated as an empty list).
Returns
An list of elements that were added.

Elements that are present in oldList but not in newList are ignored. Elements that are equal for IComparable<T>.CompareTo but have been otherwise modified will be added.

Type Constraints
T :IComparable<T> 
T :IEquatable<T> 
T :GetAddedElements 
T :newList 
T :oldList 
T :DefaultComparer<T> 
T :Instance 

◆ GetAddedElements< T >() [2/2]

static IList<T> NanoByte.Common.Collections.ListExtensions.GetAddedElements< T > ( this IList< T >?  newList,
IList< T >?  oldList,
IComparer< T >  comparer 
)
inlinestatic

Assumes two sorted lists. Determines which elements are present in newList but not in oldList .

Parameters
newListThe new list of elements; can be null (will be treated as an empty list).
oldListThe original list of elements; can be null (will be treated as an empty list).
comparerAn object that compares to elements to determine which one is bigger.
Returns
An list of elements that were added.

Elements that are present in oldList but not in newList are ignored. Elements that are equal for IComparable<T>.CompareTo but have been otherwise modified will be added.

◆ RemoveLast< T >()

static void NanoByte.Common.Collections.ListExtensions.RemoveLast< T > ( this List< T >  list,
int  number = 1 
)
inlinestatic

Removes the last n elements from the list.

Parameters
listThe list to remove the elements from.
numberThe number of elements to remove.

The documentation for this class was generated from the following file: