Class LINQExtensions
Provides static extension methods for performing common LINQ operations on IEnumerable<T> and IQueryable<T> collections.
Namespace: CapyKit.Extensions
Assembly: CapyKit.dll
Syntax
public static class LINQExtensions
Methods
Distinct<T, U>(IEnumerable<T>, Func<T, U>)
Enumerates distinct items in this collection as defined by the key property.
Declaration
public static IEnumerable<T> Distinct<T, U>(this IEnumerable<T> items, Func<T, U> property)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | The items to act on. |
| Func<T, U> | property | The property. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumerator that allows foreach to be used to process distinct items in this collection. |
Type Parameters
| Name | Description |
|---|---|
| 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.
Declaration
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source, Func<T, bool> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | source | The source to act on. |
| Func<T, bool> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumerator that allows foreach to be used to process remove in this collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
Filter<T>(IQueryable<T>, Expression<Func<T, bool>>)
Filters out items matching a predicate from the collection.
Declaration
public static IQueryable<T> Filter<T>(this IQueryable<T> source, Expression<Func<T, bool>> predicate)
Parameters
| Type | Name | Description |
|---|---|---|
| IQueryable<T> | source | The source to act on. |
| Expression<Func<T, bool>> | predicate | The predicate. |
Returns
| Type | Description |
|---|---|
| IQueryable<T> | An enumerator that allows foreach to be used to process remove in this collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
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.
Declaration
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
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | source | The source to act on. |
| IEnumerable<U> | inner | The inner. |
| Func<T, TKey> | outerSelector | The outer selector. |
| Func<U, TKey> | innerSelector | The inner selector. |
| Func<T, IEnumerable<U>, R> | resultSelector | The result selector. |
| Func<T, U> | defaultGenerator | (Optional) The default generator. |
Returns
| Type | Description |
|---|---|
| IEnumerable<R> | An enumerator that allows foreach to be used to process left outter join in this collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
| U | Generic type parameter. |
| TKey | Type of the key. |
| R | Type of the r. |
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.
Declaration
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
| Type | Name | Description |
|---|---|---|
| IQueryable<T> | source | The source to act on. |
| IQueryable<U> | inner | The inner. |
| Expression<Func<T, TKey>> | outerSelector | The outer selector. |
| Expression<Func<U, TKey>> | innerSelector | The inner selector. |
| Func<T, IEnumerable<U>, R> | resultSelector | The result selector. |
| Func<T, U> | defaultGenerator | (Optional) The default generator. |
Returns
| Type | Description |
|---|---|
| IQueryable<R> | An IQueryable<R> |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
| U | Generic type parameter. |
| TKey | Type of the key. |
| R | Type of the r. |
PageCount<T>(IEnumerable<T>, int)
The number of pages of pageSize size in the given collection.
Declaration
public static int PageCount<T>(this IEnumerable<T> source, int pageSize)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | source | The source to act on. |
| int | pageSize | Size of the page. |
Returns
| Type | Description |
|---|---|
| int | An int. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
PageCount<T>(IQueryable<T>, int)
The number of pages of pageSize size in the given collection.
Declaration
public static int PageCount<T>(this IQueryable<T> source, int pageSize)
Parameters
| Type | Name | Description |
|---|---|---|
| IQueryable<T> | source | The source to act on. |
| int | pageSize | Size of the page. |
Returns
| Type | Description |
|---|---|
| int | An int. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Page<T>(IEnumerable<T>, int, int)
Get a page of items from a collection, skipping pageNumber pages of
pageSize items per page.
Declaration
public static IEnumerable<T> Page<T>(this IEnumerable<T> source, int pageNumber, int pageSize)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | source | The source to act on. |
| int | pageNumber | The page number to retrieve. |
| int | pageSize | Number of items per page. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumerator that allows foreach to be used to process page in this collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
Remarks
This method uses natural numbering starting at page 1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Page<T>(IQueryable<T>, int, int)
Get a page of items from a collection, skipping pageNumber pages of
pageSize items per page.
Declaration
public static IQueryable<T> Page<T>(this IQueryable<T> source, int pageNumber, int pageSize)
Parameters
| Type | Name | Description |
|---|---|---|
| IQueryable<T> | source | The source to act on. |
| int | pageNumber | The page number to retrieve. |
| int | pageSize | . |
Returns
| Type | Description |
|---|---|
| IQueryable<T> | An enumerator that allows foreach to be used to process page in this collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Generic type parameter. |
Remarks
This method uses natural numbering starting at page 1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |