Show / Hide Table of Contents

    Class TypeExtensions

    Type extensions

    Inheritance
    Object
    TypeExtensions
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: XData.Extensions
    Assembly: XData.docfx.dll
    Syntax
    public static class TypeExtensions

    Methods

    | Improve this Doc View Source

    ArrayCast(Type, ICollection)

    Cast object array to specific type array

    Declaration
    public static object ArrayCast(this Type elementType, ICollection collection)
    Parameters
    Type Name Description
    Type elementType

    Type of result array elements

    ICollection collection

    Source collection

    Returns
    Type Description
    Object

    Typed array

    | Improve this Doc View Source

    ChangeType(Object, Type)

    Type convert

    Declaration
    public static object ChangeType(this object value, Type conversion)
    Parameters
    Type Name Description
    Object value

    Value to convert

    Type conversion

    Target type

    Returns
    Type Description
    Object

    Target converted value

    | Improve this Doc View Source

    ChangeType<T>(Object)

    Type convert

    Declaration
    public static T ChangeType<T>(this object value)
    Parameters
    Type Name Description
    Object value

    Value to convert

    Returns
    Type Description
    T

    Target converted value

    Type Parameters
    Name Description
    T

    Target type

    | Improve this Doc View Source

    ConvertTo<T>(Enum)

    Convert enumeration value to another enumeration by hash code

    Declaration
    public static T ConvertTo<T>(this Enum source)
    Parameters
    Type Name Description
    Enum source

    Source enumeration value

    Returns
    Type Description
    T

    Target enumeration value

    Type Parameters
    Name Description
    T

    Target enumeration type

    | Improve this Doc View Source

    EqualValue(Enum, Enum)

    Compare Enumeration values by hash codes

    Declaration
    public static bool EqualValue(this Enum source, Enum other)
    Parameters
    Type Name Description
    Enum source

    Source enumeration value

    Enum other

    Other enumeration value

    Returns
    Type Description
    Boolean

    Values are equal

    | Improve this Doc View Source

    GetDefault(Type)

    Get type default value

    Declaration
    public static object GetDefault(this Type type)
    Parameters
    Type Name Description
    Type type

    Type

    Returns
    Type Description
    Object

    Default value

    | Improve this Doc View Source

    GetDefault<TType>()

    Get type default value

    Declaration
    public static object GetDefault<TType>()
    Returns
    Type Description
    Object

    Default value

    Type Parameters
    Name Description
    TType

    Type

    | Improve this Doc View Source

    GetEnumKeyValuePairs(Type)

    Declaration
    public static IEnumerable<KeyValuePair<long, string>> GetEnumKeyValuePairs(this Type enumType)
    Parameters
    Type Name Description
    Type enumType
    Returns
    Type Description
    IEnumerable<KeyValuePair<Int64, String>>
    | Improve this Doc View Source

    GetEnumValue(Type, Int64)

    Returns enum id and value pair for specified id

    Declaration
    public static KeyValuePair<long, string>? GetEnumValue(this Type enumType, long id)
    Parameters
    Type Name Description
    Type enumType

    Enum type

    Int64 id

    Enum key

    Returns
    Type Description
    Nullable<KeyValuePair<Int64, String>>

    Enum id and value pair

    | Improve this Doc View Source

    GetGenericMethod(Type, String, IEnumerable<Type>)

    Returns generic method with typed arguments

    Declaration
    public static MethodInfo GetGenericMethod(this Type type, string name, IEnumerable<Type> parameterTypes)
    Parameters
    Type Name Description
    Type type

    Method type

    String name

    Method name

    IEnumerable<Type> parameterTypes

    Parameter types

    Returns
    Type Description
    MethodInfo

    Reflection method info

    Exceptions
    Type Condition
    XDataRuntimeException

    Method name can not be null or empty

    XDataRuntimeException

    Method parameter types can not be null

    | Improve this Doc View Source

    GetLocalizedEnumKeyValuePairs(Type)

    Returns id and name pairs for all enum values

    Declaration
    public static IEnumerable<KeyValuePair<long, string>> GetLocalizedEnumKeyValuePairs(this Type enumType)
    Parameters
    Type Name Description
    Type enumType

    Enum type

    Returns
    Type Description
    IEnumerable<KeyValuePair<Int64, String>>

    Sequence of id and name pairs for all enum values

    | Improve this Doc View Source

    GetLocalizedEnumValue(Type, Int64)

    Returns enum id and localized value pair for specified id

    Declaration
    public static KeyValuePair<long, string>? GetLocalizedEnumValue(this Type enumType, long id)
    Parameters
    Type Name Description
    Type enumType

    Enum type

    Int64 id

    Enum key

    Returns
    Type Description
    Nullable<KeyValuePair<Int64, String>>

    Enum id and localized value pair

    | Improve this Doc View Source

    GetRealType(Type)

    Get Generic base type

    Declaration
    public static Type GetRealType(this Type type)
    Parameters
    Type Name Description
    Type type

    Type

    Returns
    Type Description
    Type

    Base type

    | Improve this Doc View Source

    Implements<T>(Type, T)

    Test type implements an interface

    Declaration
    public static bool Implements<T>(this Type type, T interfaceType)
        where T : Type
    Parameters
    Type Name Description
    Type type

    Type

    T interfaceType

    Interface

    Returns
    Type Description
    Boolean

    Type is implements an interface

    Type Parameters
    Name Description
    T

    Interface type

    | Improve this Doc View Source

    InvokeMethod(Object, Expression<Action>, BindingFlags)

    Invoke method with replacing base object type wrapper

    Declaration
    public static void InvokeMethod(this object obj, Expression<Action> expr, BindingFlags bindingFlags = BindingFlags.Default)
    Parameters
    Type Name Description
    Object obj

    Object to invoke method with

    Expression<Action> expr

    Call expression

    BindingFlags bindingFlags

    Binding flags

    Exceptions
    Type Condition
    XDataRuntimeException
    | Improve this Doc View Source

    InvokeMethod(Object, Type[], Expression<Action>, BindingFlags)

    Invoke generic method wrapper

    Declaration
    public static void InvokeMethod(this object obj, Type[] types, Expression<Action> expr, BindingFlags bindingFlags = BindingFlags.Default)
    Parameters
    Type Name Description
    Object obj

    Object to invoke method (set null to call static method)

    Type[] types

    Generic arguments types array

    Expression<Action> expr

    Call expression (set generic arguments to any valid types)

    BindingFlags bindingFlags

    Binding flags

    Exceptions
    Type Condition
    XDataRuntimeException
    | Improve this Doc View Source

    InvokeMethod<TRet>(Object, Expression<Func<TRet>>, BindingFlags)

    Invoke method with replacing base object type wrapper

    Declaration
    public static TRet InvokeMethod<TRet>(this object obj, Expression<Func<TRet>> expr, BindingFlags bindingFlags = BindingFlags.Default)
    Parameters
    Type Name Description
    Object obj

    Object to invoke method with

    Expression<Func<TRet>> expr

    Call expression

    BindingFlags bindingFlags

    Binding flags

    Returns
    Type Description
    TRet

    Call return value

    Type Parameters
    Name Description
    TRet

    Return value type

    Exceptions
    Type Condition
    XDataRuntimeException
    | Improve this Doc View Source

    InvokeMethod<TRet>(Object, Type[], Expression<Func<TRet>>, BindingFlags)

    Invoke generic method wrapper

    Declaration
    public static TRet InvokeMethod<TRet>(this object obj, Type[] types, Expression<Func<TRet>> expr, BindingFlags bindingFlags = BindingFlags.Default)
    Parameters
    Type Name Description
    Object obj

    Object to invoke method (set null to call static method)

    Type[] types

    Generic arguments types array

    Expression<Func<TRet>> expr

    Call expression (set generic arguments to any valid types)

    BindingFlags bindingFlags

    Binding flags

    Returns
    Type Description
    TRet

    Call return value

    Type Parameters
    Name Description
    TRet

    Return value type

    Exceptions
    Type Condition
    XDataRuntimeException
    | Improve this Doc View Source

    IsBasedOn<TType>(Type)

    Check generic base type

    Declaration
    public static bool IsBasedOn<TType>(this Type type)
    Parameters
    Type Name Description
    Type type

    Generic type

    Returns
    Type Description
    Boolean

    Generic type is based on TType

    Type Parameters
    Name Description
    TType

    Base type to check

    | Improve this Doc View Source

    IsBinary(Type)

    Check Lob type

    Declaration
    public static bool IsBinary(this Type type)
    Parameters
    Type Name Description
    Type type

    Type to check

    Returns
    Type Description
    Boolean

    Type is binary

    | Improve this Doc View Source

    IsEnum(Type)

    Check Enum type

    Declaration
    public static bool IsEnum(this Type type)
    Parameters
    Type Name Description
    Type type

    Type to check

    Returns
    Type Description
    Boolean

    Type is binary

    | Improve this Doc View Source

    IsNullable(Type)

    Check nullable type

    Declaration
    public static bool IsNullable(this Type type)
    Parameters
    Type Name Description
    Type type

    Type to check

    Returns
    Type Description
    Boolean

    Type is nullable

    | Improve this Doc View Source

    IsXml(Type)

    Check Xml type

    Declaration
    public static bool IsXml(this Type type)
    Parameters
    Type Name Description
    Type type

    Type to check

    Returns
    Type Description
    Boolean

    Type is binary

    | Improve this Doc View Source

    NullWrap<T>(T)

    Null value wrapper

    Declaration
    public static T NullWrap<T>(T source)
        where T : class, new()
    Parameters
    Type Name Description
    T source

    Source

    Returns
    Type Description
    T

    Source or empty object of source type

    Type Parameters
    Name Description
    T

    Source type

    | Improve this Doc View Source

    NullWrap<T>(T[])

    Null value wrapper

    Declaration
    public static T[] NullWrap<T>(T[] source)
    Parameters
    Type Name Description
    T[] source

    Source array

    Returns
    Type Description
    T[]

    Source or empty array

    Type Parameters
    Name Description
    T

    Array element type

    | Improve this Doc View Source

    ParseEnum(Type, String)

    Returns id for specified enum type and string value

    Declaration
    public static long? ParseEnum(this Type enumType, string value)
    Parameters
    Type Name Description
    Type enumType

    Enum type

    String value

    String value of enum

    Returns
    Type Description
    Nullable<Int64>

    Enum id

    | Improve this Doc View Source

    ParseEnumRange(Type, ICollection<Object>)

    Parse enum values range

    Declaration
    public static object[] ParseEnumRange(this Type enumType, ICollection<object> values)
    Parameters
    Type Name Description
    Type enumType

    Enum type

    ICollection<Object> values

    Enum values range

    Returns
    Type Description
    Object[]

    Enum id array

    See Also
    ParseEnum(Type, String)
    | Improve this Doc View Source

    ParseType(String)

    Parse type full name

    Declaration
    public static Type ParseType(this string typeFullName)
    Parameters
    Type Name Description
    String typeFullName
    Returns
    Type Description
    Type
    | Improve this Doc View Source

    TryConvert<T, TResult>(T, Func<T, TResult>)

    Try to convert value

    Declaration
    public static TResult TryConvert<T, TResult>(this T source, Func<T, TResult> convert)
        where T : class
    Parameters
    Type Name Description
    T source

    Source value

    Func<T, TResult> convert

    Conversion logic

    Returns
    Type Description
    TResult

    Converted value or default of TResult

    Type Parameters
    Name Description
    T

    Source type

    TResult

    Result type

    | Improve this Doc View Source

    TryConvert<T, TResult>(T, Func<T, TResult>, TResult)

    Try to convert value

    Declaration
    public static TResult TryConvert<T, TResult>(this T source, Func<T, TResult> convert, TResult defaultValue)
        where T : class
    Parameters
    Type Name Description
    T source

    Source value

    Func<T, TResult> convert

    Conversion logic

    TResult defaultValue

    Default result value

    Returns
    Type Description
    TResult

    Converted value or default of TResult

    Type Parameters
    Name Description
    T

    Source type

    TResult

    Result type

    • Improve this Doc
    • View Source
    Back to top Generated by DocFX