Class LINQExtensions
Namespace: CapyKit.Extensions
Assembly: CapyKit.dll
Provides static extension methods for performing common LINQ operations on System.Collections.Generic.IEnumerable`1 and System.Linq.IQueryable`1 collections.
public static class LINQExtensions
Inheritance
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Extension Methods
ObjectExtensions.UpdateProperties(object, object)
Methods
Distinct<T, U>(IEnumerable<T>, Func<T, U>)
Enumerates distinct items in this collection as defined by the key property.
public static IEnumerable<T> Distinct<T, U>(this IEnumerable<T> items, Func<T, U> property)
Parameters
items IEnumerable<T>
The items to act on.
property Func<T, U>
The property.
Returns
IEnumerable<T>
An enumerator that allows foreach to be used to process distinct items in this collection.
Type Parameters
T
Generic type parameter of the parent object.
U
Generic type parameter property value.
Filter<T>(IEnumerable<T>, Func<T, bool>)
Filters out items matching a predicate from the collection.
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source, Func<T, bool> predicate)
Parameters
source IEnumerable<T>
The source to act on.
The predicate.
Returns
IEnumerable<T>
An enumerator that allows foreach to be used to process remove in this collection.
Type Parameters
T
Generic type parameter.
Filter<T>(IQueryable<T>, Expression<Func<T, bool>>)
Filters out items matching a predicate from the collection.
public static IQueryable<T> Filter<T>(this IQueryable<T> source, Expression<Func<T, bool>> predicate)
Parameters
source IQueryable<T>
The source to act on.
predicate Expression<Func<T, bool>>
The predicate.
Returns
IQueryable<T>
An enumerator that allows foreach to be used to process remove in this collection.
Type Parameters
T
Generic type parameter.
LeftOuterJoin<T, U, TKey, R>(IQueryable<T>, IQueryable<U>, Expression<Func<T, TKey>>, Expression<Func<U, TKey>>, Func<T, IEnumerable<U>, R>, Func<T, U>)
An IQueryable<T> extension method that left outer join.
public static IQueryable<R> LeftOuterJoin<T, U, TKey, R>(this IQueryable<T> source, IQueryable<U> inner, Expression<Func<T, TKey>> outerSelector, Expression<Func<U, TKey>> innerSelector, Func<T, IEnumerable<U>, R> resultSelector, Func<T, U> defaultGenerator = null)
Parameters
source IQueryable<T>
The source to act on.
inner IQueryable<U>
The inner.
outerSelector Expression<Func<T, TKey>>
The outer selector.
innerSelector Expression<Func<U, TKey>>
The inner selector.
resultSelector Func<T, IEnumerable<U>, R>
The result selector.
defaultGenerator Func<T, U>
(Optional) The default generator.
Returns
IQueryable<R>
An IQueryable<R>
Type Parameters
T
Generic type parameter.
U
Generic type parameter.
TKey
Type of the key.
R
Type of the r.
LeftOuterJoin<T, U, TKey, R>(IEnumerable<T>, IEnumerable<U>, Func<T, TKey>, Func<U, TKey>, Func<T, IEnumerable<U>, R>, Func<T, U>)
An IEnumable<T> extension method that left outer join.
public static IEnumerable<R> LeftOuterJoin<T, U, TKey, R>(this IEnumerable<T> source, IEnumerable<U> inner, Func<T, TKey> outerSelector, Func<U, TKey> innerSelector, Func<T, IEnumerable<U>, R> resultSelector, Func<T, U> defaultGenerator = null)
Parameters
source IEnumerable<T>
The source to act on.
inner IEnumerable<U>
The inner.
outerSelector Func<T, TKey>
The outer selector.
innerSelector Func<U, TKey>
The inner selector.
resultSelector Func<T, IEnumerable<U>, R>
The result selector.
defaultGenerator Func<T, U>
(Optional) The default generator.
Returns
IEnumerable<R>
An enumerator that allows foreach to be used to process left outter join in this collection.
Type Parameters
T
Generic type parameter.
U
Generic type parameter.
TKey
Type of the key.
R
Type of the r.
Page<T>(IEnumerable<T>, int, int)
Get a page of items from a collection, skipping pageNumber pages of
pageSize items per page.
public static IEnumerable<T> Page<T>(this IEnumerable<T> source, int pageNumber, int pageSize)
Parameters
source IEnumerable<T>
The source to act on.
pageNumber int
The page number to retrieve.
pageSize int
Number of items per page.
Returns
IEnumerable<T>
An enumerator that allows foreach to be used to process page in this collection.
Type Parameters
T
Generic type parameter.
Remarks
This method uses natural numbering starting at page 1.
Exceptions
Thrown when pageNumber is less than 1 or if
pageSize is less than
1.
Page<T>(IQueryable<T>, int, int)
Get a page of items from a collection, skipping pageNumber pages of
pageSize items per page.
public static IQueryable<T> Page<T>(this IQueryable<T> source, int pageNumber, int pageSize)
Parameters
source IQueryable<T>
The source to act on.
pageNumber int
The page number to retrieve.
pageSize int
.
Returns
IQueryable<T>
An enumerator that allows foreach to be used to process page in this collection.
Type Parameters
T
Generic type parameter.
Remarks
This method uses natural numbering starting at page 1.
Exceptions
Thrown when pageNumber is less than 1 or if
pageSize is less than
1.
PageCount<T>(IEnumerable<T>, int)
The number of pages of pageSize size in the given collection.
public static int PageCount<T>(this IEnumerable<T> source, int pageSize)
Parameters
source IEnumerable<T>
The source to act on.
pageSize int
Size of the page.
Returns
An int.
Type Parameters
T
Generic type parameter.
Exceptions
Thrown when pageSize is less than 1.
PageCount<T>(IQueryable<T>, int)
The number of pages of pageSize size in the given collection.
public static int PageCount<T>(this IQueryable<T> source, int pageSize)
Parameters
source IQueryable<T>
The source to act on.
pageSize int
Size of the page.
Returns
An int.
Type Parameters
T
Generic type parameter.
Exceptions
Thrown when pageSize is less than 1.