mk.helpers
Search Results for

    Show / Hide Table of Contents

    Class EnumerableExtensions

    Provides extension methods for working with IEnumerable<T> collections.

    Inheritance
    object
    EnumerableExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: mk.helpers.Types
    Assembly: mk.helpers.dll
    Syntax
    public static class EnumerableExtensions

    Methods

    CountAsync<T>(IAsyncEnumerable<T>)

    Declaration
    public static Task<int> CountAsync<T>(this IAsyncEnumerable<T> source)
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source
    Returns
    Type Description
    Task<int>
    Type Parameters
    Name Description
    T

    FilterByReference<TSource, TOrder>(IEnumerable<TSource>, IEnumerable<TOrder>, Func<TSource, TOrder, bool>)

    Filters items from a source collection based on a comparison predicate against a reference collection.

    Declaration
    public static IEnumerable<TSource> FilterByReference<TSource, TOrder>(this IEnumerable<TSource> source, IEnumerable<TOrder> orderReference, Func<TSource, TOrder, bool> comparisonPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source collection from which to filter items.

    IEnumerable<TOrder> orderReference

    The reference collection used for comparison.

    Func<TSource, TOrder, bool> comparisonPredicate

    A predicate that determines whether an item in the source collection should be included based on the reference collection.

    Returns
    Type Description
    IEnumerable<TSource>

    An IEnumerable<TSource> containing items from the source collection that satisfy the comparison predicate.

    Type Parameters
    Name Description
    TSource

    The type of elements in the source collection.

    TOrder

    The type of elements in the reference collection.

    Remarks

    This method filters items from the source collection based on a comparison predicate against a reference collection. The comparisonPredicate function is used to determine if an item should be included in the result.

    IsAnyOf<T>(T, params T[])

    Checks if an item is any of a given list of items.

    Declaration
    public static bool IsAnyOf<T>(this T source, params T[] list)
    Parameters
    Type Name Description
    T source

    The source item to check.

    T[] list

    The list of items to check against.

    Returns
    Type Description
    bool

    true if the source item is any of the items in the list; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of elements in the collection.

    Median<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)

    Extension method to calculate the median of a sequence of numeric values using a selector. Supported types are int, decimal, double, and long.

    Declaration
    public static TResult Median<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) where TResult : struct, IComparable<TResult>, IConvertible
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    An IEnumerable containing the elements.

    Func<TSource, TResult> selector

    A function to extract the numeric value from each element.

    Returns
    Type Description
    TResult

    The median value of the numeric list.

    Type Parameters
    Name Description
    TSource

    The type of the elements in the source collection.

    TResult

    The numeric type of the values returned by the selector (int, decimal, double, long).

    Exceptions
    Type Condition
    ArgumentException

    Thrown when the source sequence is empty.

    PagedAsync<T>(IAsyncEnumerable<T>, int, int)

    Declaration
    public static Task<PagedResult<T>> PagedAsync<T>(this IAsyncEnumerable<T> source, int page, int pageSize) where T : class
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source
    int page
    int pageSize
    Returns
    Type Description
    Task<PagedResult<T>>
    Type Parameters
    Name Description
    T

    Paged<T>(IEnumerable<T>, int, int)

    Implements paging on an IEnumerable<T> source.

    Declaration
    public static PagedResult<T> Paged<T>(this IEnumerable<T> source, int page, int pageSize) where T : class
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source collection.

    int page

    The current page number.

    int pageSize

    The number of items per page.

    Returns
    Type Description
    PagedResult<T>

    A PagedResult<T> containing the paged data.

    Type Parameters
    Name Description
    T

    The type of elements in the collection.

    RemoveDuplicates<TSource>(IEnumerable<TSource>, Func<TSource, TSource, bool>)

    Removes duplicate items from a collection based on a comparison predicate.

    Declaration
    public static IEnumerable<TSource> RemoveDuplicates<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, bool> comparisonPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source collection to remove duplicates from.

    Func<TSource, TSource, bool> comparisonPredicate

    A predicate to determine duplicate items.

    Returns
    Type Description
    IEnumerable<TSource>

    An IEnumerable<TSource> containing unique elements based on the comparison predicate.

    Type Parameters
    Name Description
    TSource

    The type of elements in the source collection.

    SkipAsync<T>(IAsyncEnumerable<T>, int)

    Declaration
    public static IAsyncEnumerable<T> SkipAsync<T>(this IAsyncEnumerable<T> source, int count)
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source
    int count
    Returns
    Type Description
    IAsyncEnumerable<T>
    Type Parameters
    Name Description
    T

    SortByReference(List<string>, List<string>)

    Declaration
    public static List<string> SortByReference(this List<string> listToSort, List<string> orderReference)
    Parameters
    Type Name Description
    List<string> listToSort
    List<string> orderReference
    Returns
    Type Description
    List<string>

    SortByReference<TSource, TOrder>(IEnumerable<TSource>, IEnumerable<TOrder>, Func<TSource, TOrder, bool>)

    Sorts a collection based on the order of a reference collection using a custom comparison predicate.

    Declaration
    public static IEnumerable<TSource> SortByReference<TSource, TOrder>(this IEnumerable<TSource> source, IEnumerable<TOrder> orderReference, Func<TSource, TOrder, bool> comparisonPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source collection to be sorted.

    IEnumerable<TOrder> orderReference

    The reference collection that defines the desired order.

    Func<TSource, TOrder, bool> comparisonPredicate

    A custom comparison predicate that takes elements from both collections and returns a boolean indicating their relative order.

    Returns
    Type Description
    IEnumerable<TSource>

    A new IEnumerable<TSource> sorted based on the custom comparison predicate.

    Type Parameters
    Name Description
    TSource

    The type of elements in the source collection.

    TOrder

    The type of elements in the reference collection.

    Remarks

    This method sorts the source collection based on the order of elements in the reference collection.

    It allows you to specify a custom comparison predicate that determines the sorting order based on elements from both collections.

    If a key in the source collection cannot be found in the orderReference collection, it is placed at the end of the sorted result.

    TakeAsync<T>(IAsyncEnumerable<T>, int)

    Declaration
    public static IAsyncEnumerable<T> TakeAsync<T>(this IAsyncEnumerable<T> source, int count)
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source
    int count
    Returns
    Type Description
    IAsyncEnumerable<T>
    Type Parameters
    Name Description
    T

    ToListAsync<T>(IAsyncEnumerable<T>)

    Declaration
    public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source)
    Parameters
    Type Name Description
    IAsyncEnumerable<T> source
    Returns
    Type Description
    Task<List<T>>
    Type Parameters
    Name Description
    T

    Yield<T>(T)

    Yields a single item as an IEnumerable<T>.

    Declaration
    public static IEnumerable<T> Yield<T>(this T obj)
    Parameters
    Type Name Description
    T obj

    The item to yield.

    Returns
    Type Description
    IEnumerable<T>

    An IEnumerable<T> containing the item.

    Type Parameters
    Name Description
    T

    The type of the item.

    In this article
    Back to top mk.helpers - MIT License