Liquid Studio Documentation
Data Mapping / Generated Data Mapper Code for C#
In This Topic
    Generated Data Mapper Code for C#
    In This Topic

    Once you have created a transform it's possible to compile it to C#. The generated code is split into 2 projects, a class library containing the transform and an executable stub that can be used to run the transform from the command line.

    Example

    Let's walk through an example and look at the options and investigate the code.

    First of all we need a transform. I'm using the "Filter By Price" sample form the Booktstore project.

    The compilation settings can be accessed via the "Configure Debugger" button on the toolbar. These settings allow you to control the target .Net framework, file locations, namespaces, as well as giving you the option of just generating the dll/exe without outputting the code. For a full description of the settings see the C# Debugger Options help page.

    For this example we will go with the default settings, this will output the source code for a dll and exe for the latest version of visual studio.

    To start the compilation use the compile button.

    This should also give you the option of automatically opening the project in visual studio.

    Once in the visual studio environment you will notice the 2 projects (dll and exe).

    The executable is just a stub which processes command line arguments and invokes the transform code in the dll.

    The dll contains the actual code which performs the transform, it contain a class which implements the IExecutableTransform interface, in this example the class is called GeneratedTransform.

    Assumption about the structure of the GeneratedTransform class should not be made as it may change in future releases, however by convention it will always have a default constructor and one that accepts a ParameterCollection, and will implement the IExecutableTransform interface which will have an execute method.

    As you can see if you examine the code in the class GeneratedTransform, it defines 2 variables _OutputFileName & _SourceFileName which are given a default value taken from the source transform. These values can be overridden by setting properties in the ParameterCollection passed to the constructor, you can find the names of the parameters in the InitializeParameterVariables function.

    The parameters that a transform uses depends on the components used within it. SourceFileName comes from the default source filename specified in the XML Source document and OutputFileName comes from the default output filename specified in the xml file writer. In some cases transforms are created that have input parameters that are mandatory, a transform will throw an exception if a mandatory input field is not specified.

    A transform can be executed via the IExecutableTransform.Execute method. If an error is encountered an exception is raised and execution is stopped.

    Once a transform is completed and is no longer needed (even if it failed) it MUST be Disposed of. Failure to do this could tie up file and database handles longer than required.

     

    See Also