Search Results for

    Show / Hide Table of Contents

    Class TypeExtensions

    Static extension helper methods on Type.

    Inheritance
    Object
    TypeExtensions
    Namespace: actionETL
    Assembly: actionETL.dll
    Syntax
    public static class TypeExtensions

    Methods

    DisplayName(Type)

    The display name of a type, which in several cases will be shorter and more readable than Type.FullName.

    Declaration
    public static string DisplayName(this Type type)
    Parameters
    Type Name Description
    Type type

    The type.

    Returns
    Type Description
    String

    A type name, which in the following cases will be shortened:

    NullableSystem.Boolean?
    GenericSystem.Collections.Generic.List<System.Boolean>
    ArraySystem.Boolean[], with commas in the brackets for multi-dimensional arrays
    Other types will return FullName.

    Exceptions
    Type Condition
    ArgumentNullException

    type

    GetFieldsAndPropertiesInOrder(Type, BindingFlags)

    Gets the fields and properties of a single type, in a well defined order, either via reflection, or from a cache if the type has been queried previously.

    Note that while this would include a member that is a struct, it would not include the members inside that struct. Also see TypeRowSchema, which does include columns in column schemas (i.e. inside embedded struct members).

    The order of the returned members is controlled with the OrderAttribute, using an ordering index:

    OrderAttribute with index: The index is explicitly provided. It must be in the range: [0, 9999], [20000,29999], [40000,49999], or [60000,69999].

    OrderAttribute without index: The member will automatically get an index and be ordered on
    the declaration order in the source file. This allows managing the order by simply moving the members around in the row class. Base class members will come before derived class members, and for any partial classes, the members are first sorted on the filename from CallerFilePathAttribute. By default they will get an index in the range [10000,19999], or in the range [50000,59999] if setting afterAlphabetical = true.

    No OrderAttribute: These members will automatically get an index in the [30000,39999] range, in member name (ordinal case sensitive) alphabetical order.

    Declaration
    public static IReadOnlyList<MemberInfo> GetFieldsAndPropertiesInOrder(this Type type, BindingFlags bindingFlags)
    Parameters
    Type Name Description
    Type type

    The type.

    BindingFlags bindingFlags

    The binding flags that specifies which members to include. E.g. use BindingFlags.Instance | BindingFlags.Public to get all public instance members.

    Returns
    Type Description
    IReadOnlyList<MemberInfo>

    A MemberInfo readonly list with all matching fields and properties of the specified type, or an empty list if no matches found.

    Exceptions
    Type Condition
    ArgumentNullException

    type

    See Also
    OrderAttribute
    TypeRowSchema

    IsAssignableTo<T>(Type)

    Determines whether an instance of a specified type can be assigned from the current type instance. It does the same check as IsAssignableFrom(Type), except the types have swapped places (and this one uses generics).

    Declaration
    public static bool IsAssignableTo<T>(this Type fromType)
    Parameters
    Type Name Description
    Type fromType

    The 'from' type to check.

    Returns
    Type Description
    Boolean

    true if any of the following conditions is true:

    • T and the current instance represent the same type
    • The current instance is derived either directly or indirectly from T
    • T is an interface that the current instance implements
    • The current instance is a generic type parameter, and T represents one of the constraints of the current instance
    • The current instance represents a value type, and T represents Nullable{T}
    false if none of these conditions are true, or if c is null.

    Type Parameters
    Name Description
    T

    The 'to' type to check.

    Exceptions
    Type Condition
    ArgumentNullException

    fromType

    IsNullableType(Type)

    Determines whether a type is nullable, e.g. typeof(bool?).IsNullable() would return true.

    Note: To check if a type is either a nullable value type or a reference type, use: if (default(T) == null) ....

    Declaration
    public static bool IsNullableType(this Type theValueType)
    Parameters
    Type Name Description
    Type theValueType

    Type of the value.

    Returns
    Type Description
    Boolean

    true if the type is nullable; otherwise, false.

    Exceptions
    Type Condition
    ArgumentNullException

    theValueType

    In This Article
    Back to top Copyright © 2023 Envobi Ltd