Search Results for

    Show / Hide Table of Contents

    Class TypeColumnCopier<TFrom, TTo>

    Creates delegates that copies (including deep copy where needed) data from one row (i.e. .NET CLR type) to the other, using high performance generated code. The two rows can optionally be of different types. This facility is commonly used by dataflow workers for copying and renaming column data between input and output ports.

    Any column that requires deep copy must have a data type that support it. In particular, data types that are SingleShallow do not support deep copy. For details see Multi-copy Support.

    Specify the column mappings with IColumnMapperCommand, which will use a TypeColumnMapper<TFrom, TTo> to define column mappings between two rows.

    Alternatively, the column mappings can be specified with a TypeColumnMappings. A TypeRowMappings can also be used, although the IsRowMap property will be ignored.

    Members to be copied can be specified explicitly via name or index (e.g. copy from input column "A" to the fourth output column), as well as implicitly based on name (i.e. AutoName()). A specified field or property can also be a schema member, i.e. a struct that groups multiple fields and properties, in which case the copy applies to all contained fields and properties.

    Mappings specified with Name(), AutoName() etc. are available in Mappings, which the caller can use to manually perform any tasks, such as copy columns.

    More commonly though, the caller uses CreateCopyAction(Boolean) or CreateDeepCloneFunc() to get a delegate that performs the copy as per the mappings. The caller then calls the delegate for each pair of 'from' and 'to' rows that need copying. This delegate uses high performance generated code, and does not rely on reflection when performing the copies.

    Also see the Dataflow Column Mapping and Mapping and Copying examples, as well as IColumnMapperCommand.

    If only mapping is needed (but no copy delegates), use TypeRowMapper<TFrom, TTo> instead. Also see FromTypeColumnMapper<TFrom> and ToTypeColumnMapper<TTo>, which provide mappings when only one .NET CLR type is known.

    Note: If the mapping commands result in duplicate mappings, an exception will be thrown. Resolve this by either of:

    • Specify additional or all name parts in explicit mapping
    • Change the column (or schema) names in the from and/or to rows to avoid name clashes
    • Restrict auto-mapping to specific column schemas
    • Map offending columns explicitly by name (which will exclude them from later auto-mappings)

    Inheritance
    Object
    TypeColumnCopier<TFrom, TTo>
    Namespace: actionETL
    Assembly: actionETL.dll
    Syntax
    public class TypeColumnCopier<TFrom, TTo>
        where TFrom : class where TTo : class
    Type Parameters
    Name Description
    TFrom

    The source 'from' type, which must be a class.

    TTo

    The target 'to' type, which must be a class.

    Constructors

    TypeColumnCopier(TypeColumnMappings)

    Initializes a new instance of the TypeColumnCopier<TFrom, TTo> class, which defines mappings betweens fields, properties, table columns etc., and creates high performance generated code for copying the fields and properties between the two types.

    This overload takes the mapping result as a parameter.

    Declaration
    public TypeColumnCopier(TypeColumnMappings typeColumnMappings)
    Parameters
    Type Name Description
    TypeColumnMappings typeColumnMappings

    The mapping result of a TypeColumnMapper<TFrom, TTo> or a TypeRowMapper<TFrom, TTo>.

    Exceptions
    Type Condition
    ArgumentNullException

    typeColumnMappings

    TypeColumnCopier(Action<IColumnMapperCommand>)

    Initializes a new instance of the TypeColumnCopier<TFrom, TTo> class, which defines mappings betweens fields, properties, table columns etc., and creates high performance generated code for copying the fields and properties between the two types.

    This overload takes the mapping action as a parameter.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    Declaration
    public TypeColumnCopier(Action<IColumnMapperCommand> columnMapperCommandAction)
    Parameters
    Type Name Description
    Action<IColumnMapperCommand> columnMapperCommandAction

    An action that executes commands that define which columns to copy, e.g. mapping two columns by name:

    cbc => cbc.Name("ColumnWithSameName").Name("FromColumn", "ToColumn")

    See IColumnMapperCommand for details.

    Exceptions
    Type Condition
    ArgumentNullException

    columnMapperCommandAction

    Properties

    Mappings

    Gets the column mappings as well as type and other information about the 'from' and 'to' sides.

    Declaration
    public TypeColumnMappings Mappings { get; }
    Property Value
    Type Description
    TypeColumnMappings

    Methods

    CreateCopyAction(Boolean)

    Creates an action that copies fields and properties from one class instance or struct to another class instance, optionally of a different type, according to Mappings, using high performance generated code.

    Use this method when you already have the target row available, use CreateDeepCloneFunc() when the delegate should instantiate the target row before copying to it.

    The created action has a signature corresponding to:

    void Copy(TFrom from, TTo to)

    Declaration
    public Action<TFrom, TTo> CreateCopyAction(bool forceDeepCopy)
    Parameters
    Type Name Description
    Boolean forceDeepCopy

    If set to true, all columns will be copied using deep copy, if they support it. This is useful if e.g. the worker is making multiple copies of the same row.

    If set to false, the first copy of a source member column will be a shallow copy. Any subsequent copies to other target members (i.e. copying the same 'from' column to multiple 'to' columns) will be deep copies (if the member type supports it).

    Returns
    Type Description
    Action<TFrom, TTo>

    The action, which takes the following parameters:

    fromThe class instance or struct to copy from
    toThe class instance to copy to
    When called, the action performs the specified copy. Any unmapped target columns will have their default value.

    If there are no members or no mappings found, a no-op action is returned.

    Exceptions
    Type Condition
    InvalidOperationException
    • Dataflow type not supported
    • Dataflow type does not support multiple or deep copies

    CreateDeepCloneFunc()

    Creates a function that performs a deep copy of fields and properties from one class instance or struct to a newly allocated class instance, optionally of a different type, according to Mappings, using high performance generated code.

    Use this method when the delegate should instantiate the target row before copying to it, use CreateCopyAction(Boolean) when you already have the target row available.

    The created function has a signature corresponding to:

    TTo DeepClone(TFrom from)

    Declaration
    public Func<TFrom, TTo> CreateDeepCloneFunc()
    Returns
    Type Description
    Func<TFrom, TTo>

    The function, which takes the following parameter:

    fromThe class instance or struct to copy from
    When called, the function returns the newly created instance, with members populated according to previously defined mappings. Any unmapped target columns will have their default value.

    If there are no members or no mappings found, a no-op function is returned.

    Exceptions
    Type Condition
    InvalidOperationException
    • Dataflow type not supported
    • Dataflow type does not support multiple or deep copies

    See Also

    TypeColumnMappings
    TypeRowMappings
    TypeRowMapper<TFrom, TTo>
    IRowMapperCommand
    FromTypeColumnMapper<TFrom>
    ToTypeColumnMapper<TTo>
    In This Article
    Back to top Copyright © 2023 Envobi Ltd