Class EnumerableExtensions
- Namespace
 - ChartTools.Extensions.Linq
 
- Assembly
 - ChartTools.dll
 
Provides a set of extension methods for IEnumerable<T>.
public static class EnumerableExtensions
  - Inheritance
 - 
      
      EnumerableExtensions
 
- Inherited Members
 
Methods
AlternateBy<T, TKey>(IEnumerable<IEnumerable<T>>, Func<T, TKey>)
Combines enumerables by alternating between each source for every item based on a key.
public static IEnumerable<T> AlternateBy<T, TKey>(this IEnumerable<IEnumerable<T>> sources, Func<T, TKey> selector) where TKey : IComparable<TKey>
  Parameters
sourcesIEnumerable<IEnumerable<T>>- Set of enumerables to alternate between
 selectorFunc<T, TKey>Selector function returning the alternate key from an item
Returns
- IEnumerable<T>
 Combined items from all enumerables, taking the next item with the smallest key from each enumerable.
Type Parameters
TType of root items
TKeyType of key used to compare items when alternating
Remarks
When the end of an enumerable is reached, alternating continues while skipping that enumerable until all are finished.
Alternate<T>(IEnumerable<IEnumerable<T>>)
Combines enumerables by alternating between each source for every item.
public static IEnumerable<T> Alternate<T>(this IEnumerable<IEnumerable<T>> sources)
  Parameters
sourcesIEnumerable<IEnumerable<T>>Set of enumerables to alternate between
Returns
- IEnumerable<T>
 Combined items from all enumerables, taking one item from each before looping.
Type Parameters
TType of root items
Remarks
When the end of an enumerable is reached, alternating continues while skipping that enumerable until all are finished.
Distinct<T>(IEnumerable<T>, EqualityComparison<T?>)
Returns distinct elements of a collection using a method to determine the equality of elements.
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> source, EqualityComparison<T?> comparison)
  Parameters
sourceIEnumerable<T>Collection to get distinct items from
comparisonEqualityComparison<T>Method determining if two elements are the same
Returns
- IEnumerable<T>
 
Type Parameters
TType of items in the collection
FirstOrDefault<T>(IEnumerable<T>, Predicate<T>, T?, out bool)
Gets the first item that meets a condition from a collection or a default value if no such item was found.
public static T? FirstOrDefault<T>(this IEnumerable<T> source, Predicate<T> predicate, T? defaultValue, out bool returnedDefault)
  Parameters
sourceIEnumerable<T>Collection to get the first item of
predicatePredicate<T>Condition to compare items against
defaultValueTValue to return if no items meeting the condition were found
returnedDefaultbooltrue if no items meeting the condition were found
Returns
- T
 
Type Parameters
TType of items in the collection
NonNull<T>(IEnumerable<T?>)
Excludes null item from a set of nullable values.
public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> source) where T : struct
  Parameters
sourceIEnumerable<T?>Set of values wrapped in Nullable<T>
Returns
- IEnumerable<T>
 Set of the nullable values unwrapped to the underlying type with null items excluded.
Type Parameters
TUnderlying value type
NonNull<T>(IEnumerable<T?>)
Excludes null items from a set of references.
public static IEnumerable<T> NonNull<T>(this IEnumerable<T?> source)
  Parameters
sourceIEnumerable<T>
Returns
- IEnumerable<T>
 
Type Parameters
TType of items of references types or boxed values
ReplaceSection<T>(IEnumerable<T>, SectionReplacement<T>)
Replaces a section from a collection with other items.
public static IEnumerable<T> ReplaceSection<T>(this IEnumerable<T> source, SectionReplacement<T> replacement)
  Parameters
sourceIEnumerable<T>Items to replace a section in
replacementSectionReplacement<T>Set of rules defining the replacement
Returns
- IEnumerable<T>
 Items with the specified section replaced
Type Parameters
TType of items in the collection
Remarks
Items that match StartReplace or EndReplace are not included in the output.
ReplaceSections<T>(IEnumerable<T>, IEnumerable<SectionReplacement<T>>)
Replaces multiple sections of items from a collection.
public static IEnumerable<T> ReplaceSections<T>(this IEnumerable<T> source, IEnumerable<SectionReplacement<T>> replacements)
  Parameters
sourceIEnumerable<T>Items to replace sections in
replacementsIEnumerable<SectionReplacement<T>>Set of definitions of section replacements
Returns
- IEnumerable<T>
 Items with the specified section replaced
Type Parameters
TType of items in the collection
Remarks
Items that match StartReplace or EndReplace are not included in the output.
Replace<T>(IEnumerable<T>, Predicate<T>, T)
Replaces items that meet a condition with another item.
public static IEnumerable<T> Replace<T>(this IEnumerable<T> source, Predicate<T> predicate, T replacement)
  Parameters
sourceIEnumerable<T>The collection to replace the items of
predicatePredicate<T>A function that determines if an item must be replaced
replacementTThe item to replace items with
Returns
- IEnumerable<T>
 
Type Parameters
TType of items in the collection
TryGetFirstOfType<TResult>(IEnumerable, out TResult)
Tries to get the first item of a given type in a collection.
public static bool TryGetFirstOfType<TResult>(this IEnumerable source, out TResult result)
  Parameters
sourceIEnumerableSource of items
resultTResultFound item
Returns
Type Parameters
TResultType to get items of
TryGetFirst<T>(IEnumerable<T>, Predicate<T>, out T?)
Tries to get the first item that meets a condition from a collection.
public static bool TryGetFirst<T>(this IEnumerable<T> source, Predicate<T> predicate, out T? item) where T : notnull
  Parameters
sourceIEnumerable<T>Collection to get the first item of
predicatePredicate<T>Method that returns true if a given item meets the condition
itemTFound item
Returns
Type Parameters
TType of items in the collection
TryGetFirst<T>(IEnumerable<T>, out T)
Tries to get the first element of a collection.
public static bool TryGetFirst<T>(this IEnumerable<T> source, out T result)
  Parameters
sourceIEnumerable<T>Source of items
resultTFound item
Returns
Type Parameters
TType of items in the collection