Search Results for

    Show / Hide Table of Contents

    Class ConvertExpressionInfo

    A class for creating Expression tree implicit conversions between two types. This is useful when creating high performance delegates at runtime using expression trees. E.g. IAggregationCommand and AdbDataReaderSource{TOutput} use this to implicitly convert between incoming and outgoing data types. You can also use it directly in your own implementations.

    Use Create(Type, Type) to create an instance that describes whether an implicit conversion can be made (HasImplicitConversion), and also can rewrite an existing expression to apply the conversion if supported (Apply(Expression)).

    Conversions are based on C# implicit conversions, where common ones are supported, while others are not supported or not applicable, see Create(Type, Type) for details.

    Inheritance
    Object
    ConvertExpressionInfo
    Namespace: actionETL
    Assembly: actionETL.dll
    Syntax
    public class ConvertExpressionInfo

    Properties

    FromType

    Gets the type to convert from.

    Declaration
    public Type FromType { get; }
    Property Value
    Type Description
    Type

    HasImplicitConversion

    Returns true if Apply(Expression) can modify an expression to implicitly convert from FromType to ToType; otherwise, false.

    Note that if IsImplicitConversionNotRequired is true, this property will also always be true.

    Declaration
    public bool HasImplicitConversion { get; }
    Property Value
    Type Description
    Boolean

    IsImplicitConversionNotRequired

    Returns true if no expression is needed to implicitly convert from FromType to ToType, e.g. due to the types being identical; otherwise, false. In either case, you can still call Apply(Expression).

    Normally, only HasImplicitConversion and Apply(Expression) are used instead of this property.

    Declaration
    public bool IsImplicitConversionNotRequired { get; }
    Property Value
    Type Description
    Boolean

    ToType

    Gets the type to convert to.

    Declaration
    public Type ToType { get; }
    Property Value
    Type Description
    Type

    Methods

    Apply(Expression)

    Wraps and returns the supplied expression with additional expressions that converts it to the ToType type.

    Declaration
    public Expression Apply(Expression fromExpression)
    Parameters
    Type Name Description
    Expression fromExpression

    From expression.

    Returns
    Type Description
    Expression

    The resulting wrapped expression. If no conversion is needed, fromExpression is returned unchanged.

    Exceptions
    Type Condition
    InvalidOperationException

    Implicit conversion between the two types is not supported.

    Create(Type, Type)

    Factory method that creates an immutable ConvertExpressionInfo instance. Use its properties to check if the implicit type conversion is supported, and to transform an Expression tree to perform the conversion.

    Conversions are based on C# implicit conversions, see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/conversions#implicit-conversions for details, where common ones are supported, and some less common ones are not supported or not applicable, as described below.

    Supported:

    • Identity conversions.
    • Implicit numeric conversions.
    • Implicit nullable conversions.
    • Implicit reference conversions, except from reference_type to an interface or delegate type T via variance conversion, or implicit conversions involving type parameters that are known to be reference types, or between two reference_types via an implicit identity or reference conversion to an intermediate reference_type followed by an identity conversion to the target type.
    • Implicit boxing conversions, except from a value type to an interface type I via variance conversion.
    • User-defined implicit conversions, except the principle of using the "most encompassing" / "most encompassed" types to select a specific user defined implicit cast.

    Not applicable:

    • Implicit enumeration conversions.
    • Implicit interpolated string conversions.
    • Null literal conversions.
    • Implicit dynamic conversions.
    • Implicit constant expression conversions.
    • Implicit conversions involving type parameters.
    • Anonymous function conversions and method group conversions.

    Declaration
    public static ConvertExpressionInfo Create(Type fromType, Type toType)
    Parameters
    Type Name Description
    Type fromType

    From type.

    Type toType

    To type.

    Returns
    Type Description
    ConvertExpressionInfo

    An immutable ConvertExpressionInfo instance.

    Exceptions
    Type Condition
    ArgumentNullException
    • fromType
    • toType

    ToString()

    Returns a String that represents this instance.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()
    In This Article
    Back to top Copyright © 2021 Envobi Ltd