Show / Hide Table of Contents

    Class TypeUtility

    This utility class is designed to make System.Type operations easier to work with.

    Inheritance
    System.Object
    TypeUtility
    Namespace: Cuemon
    Assembly: Cuemon.Core.dll
    Syntax
    public static class TypeUtility

    Methods

    | Improve this Doc

    ContainsAttributeType(Object, Boolean, Type[])

    Determines whether the specified source object contains one or more of the specified attribute target types.

    Declaration
    public static bool ContainsAttributeType(object source, bool inherit, params Type[] targets)
    Parameters
    Type Name Description
    System.Object source

    The source object to match against.

    System.Boolean inherit

    true to search the source inheritance chain to find the attributes; otherwise, false.

    System.Type[] targets

    The attribute target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source object contains one or more of the specified attribute target types; otherwise, false.

    | Improve this Doc

    ContainsAttributeType(Object, Type[])

    Determines whether the specified source object contains one or more of the specified attribute target types.

    Declaration
    public static bool ContainsAttributeType(object source, params Type[] targets)
    Parameters
    Type Name Description
    System.Object source

    The source object to match against.

    System.Type[] targets

    The attribute target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source object contains one or more of the specified attribute target types; otherwise, false.

    | Improve this Doc

    ContainsAttributeType(MemberInfo, Boolean, Type[])

    Determines whether the specified source type contains one or more of the specified attribute target types.

    Declaration
    public static bool ContainsAttributeType(MemberInfo source, bool inherit, params Type[] targets)
    Parameters
    Type Name Description
    System.Reflection.MemberInfo source

    The member to match against.

    System.Boolean inherit

    true to search the source inheritance chain to find the attributes; otherwise, false.

    System.Type[] targets

    The attribute target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified member contains one or more of the specified attribute target types; otherwise, false.

    | Improve this Doc

    ContainsAttributeType(MemberInfo, Type[])

    Determines whether the specified source type contains one or more of the specified attribute target types.

    Declaration
    public static bool ContainsAttributeType(MemberInfo source, params Type[] targets)
    Parameters
    Type Name Description
    System.Reflection.MemberInfo source

    The member to match against.

    System.Type[] targets

    The attribute target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified member contains one or more of the specified attribute target types; otherwise, false.

    | Improve this Doc

    ContainsAttributeType(Type, Boolean, Type[])

    Determines whether the specified source type contains one or more of the specified attribute target types.

    Declaration
    public static bool ContainsAttributeType(Type source, bool inherit, params Type[] targets)
    Parameters
    Type Name Description
    System.Type source

    The source type to match against.

    System.Boolean inherit

    true to search the source inheritance chain to find the attributes; otherwise, false.

    System.Type[] targets

    The attribute target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source type contains one or more of the specified attribute target types; otherwise, false.

    | Improve this Doc

    ContainsAttributeType(Type, Type[])

    Determines whether the specified source type contains one or more of the specified attribute target types.

    Declaration
    public static bool ContainsAttributeType(Type source, params Type[] targets)
    Parameters
    Type Name Description
    System.Type source

    The source type to match against.

    System.Type[] targets

    The attribute target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source type contains one or more of the specified attribute target types; otherwise, false.

    | Improve this Doc

    ContainsInterface(Object, Boolean, Type[])

    Determines whether the specified source contains one or more of the target types specified.

    Declaration
    public static bool ContainsInterface(object source, bool inherit, params Type[] targets)
    Parameters
    Type Name Description
    System.Object source

    The source object to match against.

    System.Boolean inherit

    Specifies whether to search this member's inheritance chain to find the interfaces.

    System.Type[] targets

    The target interface types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the target types specified; otherwise, false.

    | Improve this Doc

    ContainsInterface(Object, Type[])

    Determines whether the specified source contains one or more of the target types specified throughout this member's inheritance chain.

    Declaration
    public static bool ContainsInterface(object source, params Type[] targets)
    Parameters
    Type Name Description
    System.Object source

    The source object to match against.

    System.Type[] targets

    The target interface types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the target types specified throughout this member's inheritance chain; otherwise, false.

    | Improve this Doc

    ContainsInterface(Type, Boolean, Type[])

    Determines whether the specified source contains one or more of the target types specified.

    Declaration
    public static bool ContainsInterface(Type source, bool inherit, params Type[] targets)
    Parameters
    Type Name Description
    System.Type source

    The source type to match against.

    System.Boolean inherit

    Specifies whether to search this member's inheritance chain to find the interfaces.

    System.Type[] targets

    The target interface types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the target types specified; otherwise, false.

    | Improve this Doc

    ContainsInterface(Type, Type[])

    Determines whether the specified source contains one or more of the target types specified throughout this member's inheritance chain.

    Declaration
    public static bool ContainsInterface(Type source, params Type[] targets)
    Parameters
    Type Name Description
    System.Type source

    The source type to match against.

    System.Type[] targets

    The target interface types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the target types specified throughout this member's inheritance chain; otherwise, false.

    | Improve this Doc

    ContainsType(Object, Boolean, Type[])

    Determines whether the specified source/collection of source object(s) contains one or more of the specified target types.

    Declaration
    public static bool ContainsType(object source, bool treatSourceAsEnumerable, params Type[] targets)
    Parameters
    Type Name Description
    System.Object source

    The source object to match against.

    System.Boolean treatSourceAsEnumerable

    if set to true the source object is cast as an System.Collections.IEnumerable object, and the actual matching is now done against the source objects within the collection against the target types specified.

    System.Type[] targets

    The target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the specified target types; otherwise, false.

    | Improve this Doc

    ContainsType(Object, Type[])

    Determines whether the specified source contains one or more of the specified target types.

    Declaration
    public static bool ContainsType(object source, params Type[] targets)
    Parameters
    Type Name Description
    System.Object source

    The source object to match against.

    System.Type[] targets

    The target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the specified target types; otherwise, false.

    | Improve this Doc

    ContainsType(Type, Type[])

    Determines whether the specified source type contains one or more of the specified target types.

    Declaration
    public static bool ContainsType(Type source, params Type[] targets)
    Parameters
    Type Name Description
    System.Type source

    The source type to match against.

    System.Type[] targets

    The target types to be matched against.

    Returns
    Type Description
    System.Boolean

    true if the specified source contains one or more of the specified target types; otherwise, false.

    | Improve this Doc

    GetAncestorAndDescendantsOrSelfTypes(Type)

    Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the source.

    Declaration
    public static IEnumerable<Type> GetAncestorAndDescendantsOrSelfTypes(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to locate ancestor-and-descendant-or-self types from.

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

    An System.Collections.Generic.IEnumerable<T> holding the ancestor-and-descendant-or-self types from the source.

    | Improve this Doc

    GetAncestorAndDescendantsOrSelfTypes(Type, Assembly[])

    Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the source.

    Declaration
    public static IEnumerable<Type> GetAncestorAndDescendantsOrSelfTypes(Type source, params Assembly[] assemblies)
    Parameters
    Type Name Description
    System.Type source

    The source type to locate ancestor-and-descendant-or-self types from.

    System.Reflection.Assembly[] assemblies

    The assemblies to search for the source.

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

    An System.Collections.Generic.IEnumerable<T> holding the ancestor-and-descendant-or-self types from the source.

    | Improve this Doc

    GetAncestorOrSelf(Type, Type)

    Gets the ancestor-or-self System.Type from the specified source.

    Declaration
    public static Type GetAncestorOrSelf(Type source, Type sourceBaseLimit)
    Parameters
    Type Name Description
    System.Type source

    The source type to traverse.

    System.Type sourceBaseLimit

    The base limit of source.

    Returns
    Type Description
    System.Type

    The ancestor-or-self type from the specified source that is derived or equal to sourceBaseLimit.

    Exceptions
    Type Condition
    System.ArgumentNullException

    source - or - sourceBaseLimit is null.

    | Improve this Doc

    GetAncestorOrSelfTypes(Type)

    Gets a sequence of ancestor-or-self types from the source.

    Declaration
    public static IEnumerable<Type> GetAncestorOrSelfTypes(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to locate ancestor-or-self types from.

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

    An System.Collections.Generic.IEnumerable<T> holding the ancestor-or-self types from the source.

    | Improve this Doc

    GetDefaultValue(Type)

    Gets the default value of the specified type.

    Declaration
    public static object GetDefaultValue(Type type)
    Parameters
    Type Name Description
    System.Type type

    The System.Type to retrieve its default value from.

    Returns
    Type Description
    System.Object

    The default value of type.

    | Improve this Doc

    GetDescendantOrSelfTypes(Type)

    Gets a sequence of derived types from the source an it's associated System.Reflection.Assembly.

    Declaration
    public static IEnumerable<Type> GetDescendantOrSelfTypes(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to locate derived types from.

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

    An System.Collections.Generic.IEnumerable<T> holding the derived types from the source.

    | Improve this Doc

    GetDescendantOrSelfTypes(Type, Assembly[])

    Gets a sequence of derived types from the source.

    Declaration
    public static IEnumerable<Type> GetDescendantOrSelfTypes(Type source, params Assembly[] assemblies)
    Parameters
    Type Name Description
    System.Type source

    The source type to locate derived types from.

    System.Reflection.Assembly[] assemblies

    The assemblies to search for the source.

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

    An System.Collections.Generic.IEnumerable<T> holding the derived types from the source.

    | Improve this Doc

    Is<T>(Object)

    Determines whether the specified source is of T.

    Declaration
    public static bool Is<T>(object source)
    Parameters
    Type Name Description
    System.Object source

    The object to compare with T.

    Returns
    Type Description
    System.Boolean

    true if the specified source is of T; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to compare with source.

    | Improve this Doc

    IsAnonymousMethod(Type)

    Determines whether the specified source is an anonymous method (be that in a form of a delegate or lambda expression).

    Declaration
    public static bool IsAnonymousMethod(Type source)
    Parameters
    Type Name Description
    System.Type source

    The System.Type to determine is an anonymous method.

    Returns
    Type Description
    System.Boolean

    true if the specified source is an anonymous method; otherwise, false.

    | Improve this Doc

    IsComparable(Type)

    Determines whether the specified source implements either System.IComparable or System.IComparable<T>.

    Declaration
    public static bool IsComparable(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for implements of either System.IComparable or System.IComparable<T>.

    Returns
    Type Description
    System.Boolean

    true if the specified source implements either System.IComparable or System.IComparable<T>; otherwise, false.

    | Improve this Doc

    IsComparer(Type)

    Determines whether the specified source implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>.

    Declaration
    public static bool IsComparer(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for implements of either System.Collections.IComparer or System.Collections.Generic.IComparer<T>.

    Returns
    Type Description
    System.Boolean

    true if the specified source implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>; otherwise, false.

    | Improve this Doc

    IsComplex(Type[])

    Determines whether the specified sources, as a whole, is determined a complex System.Type.

    Declaration
    public static bool IsComplex(params Type[] sources)
    Parameters
    Type Name Description
    System.Type[] sources

    The System.Type (or types) to determine complexity for.

    Returns
    Type Description
    System.Boolean

    true if specified sources, as a whole, is a complex System.Type; otherwise, false.

    Exceptions
    Type Condition
    System.ArgumentNullException

    sources is null.

    | Improve this Doc

    IsDictionary(Type)

    Determines whether the specified source implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>.

    Declaration
    public static bool IsDictionary(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for implements of either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>

    Returns
    Type Description
    System.Boolean

    true if the specified source implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>; otherwise, false.

    | Improve this Doc

    IsEnumerable(Type)

    Determines whether the specified source implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>.

    Declaration
    public static bool IsEnumerable(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for implements of either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>.

    Returns
    Type Description
    System.Boolean

    true if the specified source implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>; otherwise, false.

    | Improve this Doc

    IsEqualityComparer(Type)

    Determines whether the specified source implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>.

    Declaration
    public static bool IsEqualityComparer(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for implements of either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>.

    Returns
    Type Description
    System.Boolean

    true if the specified source implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>; otherwise, false.

    | Improve this Doc

    IsKeyValuePair(Type)

    Determines whether the specified source implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair<TKey,TValue>.

    Declaration
    public static bool IsKeyValuePair(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for implements of either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair<TKey,TValue>.

    Returns
    Type Description
    System.Boolean

    true if the specified source implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair<TKey,TValue>.; otherwise, false.

    | Improve this Doc

    IsNot<T>(Object)

    Determines whether the specified source is not of T.

    Declaration
    public static bool IsNot<T>(object source)
    Parameters
    Type Name Description
    System.Object source

    The object to compare with T.

    Returns
    Type Description
    System.Boolean

    true if the specified source is not of T; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to compare with source.

    | Improve this Doc

    IsNullable(Type)

    Determines whether the specified source is a nullable System.ValueType.

    Declaration
    public static bool IsNullable(Type source)
    Parameters
    Type Name Description
    System.Type source

    The source type to check for nullable System.ValueType.

    Returns
    Type Description
    System.Boolean

    true if the specified source is nullable; otherwise, false.

    | Improve this Doc

    IsNullable<T>(T)

    Determines whether the specified source is a nullable System.ValueType.

    Declaration
    public static bool IsNullable<T>(T source)
    Parameters
    Type Name Description
    T source

    The source type to check for nullable System.ValueType.

    Returns
    Type Description
    System.Boolean

    true if the specified source is nullable; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of the source of T.

    | Improve this Doc

    IsNullable<T>(Nullable<T>)

    Determines whether the specified source is a nullable System.ValueType.

    Declaration
    public static bool IsNullable<T>(T? source)
        where T : struct
    Parameters
    Type Name Description
    System.Nullable<T> source

    The source type to check for nullable System.ValueType.

    Returns
    Type Description
    System.Boolean

    true if the specified source is nullable; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of the source of T.

    | Improve this Doc

    IsWithDefaultConstructor(Type)

    Determines whether the specified source has a default constructor.

    Declaration
    public static bool IsWithDefaultConstructor(Type source)
    Parameters
    Type Name Description
    System.Type source

    The System.Type to determine is with default constructor.

    Returns
    Type Description
    System.Boolean

    true if the specified source has a default constructor; otherwise, false.

    | Improve this Doc

    IsWithoutDefaultConstructor(Type)

    Determines whether the specified source does not have a default constructor.

    Declaration
    public static bool IsWithoutDefaultConstructor(Type source)
    Parameters
    Type Name Description
    System.Type source

    The System.Type to determine is without a default constructor.

    Returns
    Type Description
    System.Boolean

    true if the specified source does not have a default constructor; otherwise, false.

    • Improve this Doc
    • View Source
    Back to top Copyright 2008-2018 Weubphoria. All rights reserved.
    Generated by DocFX