Table of Contents

Class CollectionExtensions

Namespace
FluentCommand.Extensions
Assembly
FluentCommand.dll

Collection extension methods

public static class CollectionExtensions
Inheritance
CollectionExtensions
Inherited Members

Methods

FirstOrAdd<T>(ICollection<T>, Func<T, bool>, Func<T>)

Gets the first element from the source that passes the test specified by predicate; otherwise the valueFactory is called and the result is added to the source.

public static T FirstOrAdd<T>(this ICollection<T> source, Func<T, bool> predicate, Func<T> valueFactory)

Parameters

source ICollection<T>

An ICollection<T> to get or add an element from.

predicate Func<T, bool>

A function to test each element for a condition.

valueFactory Func<T>

The function used to generate a value when not found in the collection.

Returns

T

The value from valueFactory if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Type Parameters

T

The type of the elements of source.

RemoveAll<T>(ICollection<T>, Func<T, bool>)

Removes the all the elements that match the conditions defined by the specified predicate.

public static int RemoveAll<T>(this ICollection<T> collection, Func<T, bool> filter)

Parameters

collection ICollection<T>

The collection to remove items from.

filter Func<T, bool>

The delegate that defines the conditions of the elements to remove.

Returns

int

The number of items removed.

Type Parameters

T

Type of the items.