Show / Hide Table of Contents

    Class EnumerationExtensions

    Handy extension methods for Flags-Enums. Taken from http://hugoware.net/blog/enums-flags-and-csharp

    Inheritance
    System.Object
    EnumerationExtensions
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: OPTANO.Modeling.Common
    Assembly: Common.dll
    Syntax
    public static class EnumerationExtensions

    Methods

    Add<T>(Enum, T)

    Declaration
    public static T Add<T>(this Enum type, T value)
    Parameters
    Type Name Description
    System.Enum type
    T value
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    Has<T>(Enum, T)

    Checks if the value contains the provided type. It is NOT validated whether type.GetType() == typeof(T). Only the respective int-casts are compared!

    Declaration
    public static bool Has<T>(this Enum type, T value)
    Parameters
    Type Name Description
    System.Enum type

    The extended System.Enum.

    T value

    The flag to check for.

    Returns
    Type Description
    System.Boolean

    True, if the -flag is set in the -Enum. It is NOT validated whether type.GetType() == typeof(T). Only the respective int-casts are compared!

    Type Parameters
    Name Description
    T

    The flag enum type, that you want to check against.

    Is<T>(Enum, T)

    Declaration
    public static bool Is<T>(this Enum type, T value)
    Parameters
    Type Name Description
    System.Enum type
    T value
    Returns
    Type Description
    System.Boolean
    Type Parameters
    Name Description
    T

    PartitionEnumerable<T>(IEnumerable<T>, Int32)

    Partitions the given source into lists with partitionSize elements. The last partition might be smaller in size.

    Declaration
    public static IEnumerable<List<T>> PartitionEnumerable<T>(this IEnumerable<T> source, int partitionSize)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<T> source

    The source.

    System.Int32 partitionSize

    The partition size.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.Collections.Generic.List<T>>

    The enumerable partition.

    Type Parameters
    Name Description
    T

    The element type.

    Remove<T>(Enum, T)

    Declaration
    public static T Remove<T>(this Enum type, T value)
    Parameters
    Type Name Description
    System.Enum type
    T value
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    SelectWhere<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>, Func<TSource, Boolean>)

    Adds a filter to System.Linq.Enumerable.Select``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1}) calls.

    Declaration
    public static IEnumerable<TResult> SelectWhere<TSource, TResult>(this IEnumerable<TSource> enumerable, Func<TSource, TResult> selector, Func<TSource, bool> filter)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<TSource> enumerable

    The enumerable.

    System.Func<TSource, TResult> selector

    The selector to transfer TSource to TResult.

    System.Func<TSource, System.Boolean> filter

    The where-filter.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<TResult>
    Type Parameters
    Name Description
    TSource

    The source type.

    TResult

    The result type.

    ToHashSet<T>(IEnumerable<T>, IEqualityComparer<T>)

    Returns a hashset that contains the elements from enumerable.

    Declaration
    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> enumerable, IEqualityComparer<T> comparer = null)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<T> enumerable

    The enumerable

    System.Collections.Generic.IEqualityComparer<T> comparer

    Optional: The equality comparer.

    Returns
    Type Description
    System.Collections.Generic.HashSet<T>

    The hash set.

    Type Parameters
    Name Description
    T

    The type.

    Back to top Copyright © OPTANO GmbH generated with DocFX
    Privacy Policy | Impressum – Legal Notice