Custom Data Type Mappings

MapPrep

Custom Data Type Mappings

 

CodeGen includes several field loop tokens that emit, based on the Synergy data type of a field, an appropriate data type for use in various other languages. These tokens are  <FIELD_CSTYPE>, <FIELD_OCTYPE>, <FIELD_SNTYPE>, <FIELD_SQLTYPE> and <FIELD_VBTYPE>.

The data type mappings used by these tokens are hard coded to suitable default values within CodeGen. These default values generally follow the same rules that xfNetLink has always used when converting traditional Synergy types into .NET and Java types, and should work well in most scenarios. However if the defaults don't work in a particular scenario then it is possible to customize the values by specifying the data type mappings that you wish to use in an XML file.

The XML file must be defined in a specific way, and an example file called DataMappingsExample.xml is provided when you install or build CodeGen.

Within the XML file there are several main sections that correspond to the various languages that CodeGen supports:

Language

Field Loop Token

XML File Section

C#

<FIELD_CSTYPE>

CSharp

Objective C

<FIELD_OCTYPE>

ObjectiveC

Synergy .NET

<FIELD_SNTYPE>

SynergyDotNet

SQL

<FIELD_SQLTYPE>

SQL

Visual Basic

<FIELD_VBTYPE>

VisualBasic

Within each of these main sections there are data type mappings for each of the field types that CodeGen supports. For example, the default mappings for C# look like this:

<CSharp>    <Alpha>string</Alpha>
    <AlphaBinary>string</AlphaBinary>
    <UserAlpha>string</UserAlpha>
    <UserNumeric>string</UserNumeric>
    <UserDate>string</UserDate>
    <UserTimeStamp>string</UserTimeStamp>
    <DateYYYYMMDD>DateTime</DateYYYYMMDD>
    <DateYYMMDD>DateTime</DateYYMMDD>
    <DateYYYYJJJ>DateTime</DateYYYYJJJ>
    <DateYYJJJ>DateTime</DateYYJJJ>
    <DateYYYYPP>string</DateYYYYPP>
    <DateYYPP>string</DateYYPP>
    <NullableDateYYYYMMDD>DateTime?</NullableDateYYYYMMDD>
    <NullableDateYYMMDD>DateTime?</NullableDateYYMMDD>
    <NullableDateYYYYJJJ>DateTime?</NullableDateYYYYJJJ>
    <NullableDateYYJJJ>DateTime?</NullableDateYYJJJ>
    <TimeHHMMSS>DateTime</TimeHHMMSS>
    <TimeHHMM>DateTime</TimeHHMM>
    <NullableTimeHHMMSS>DateTime?</NullableTimeHHMMSS>
    <NullableTimeHHMM>DateTime?</NullableTimeHHMM>
    <ImpliedDecimal>decimal</ImpliedDecimal>
    <SmallDecimal>int</SmallDecimal>
    <LargeDecimal>long</LargeDecimal>
    <Integer1>int</Integer1>
    <Integer2>int</Integer2>
    <Integer4>int</Integer4>
    <Integer8>long</Integer8>
    <Boolean>bool</Boolean>
    <Enum>int</Enum>
    <Binary>char(l)</Binary>
    <StructField>String</StructField>
    <AutoSequence>long</AutoSequence>
    <AutoTime>long</AutoTime>
  </CSharp>

In some data mappings you may need to specify the length of a variable (e.g. the Alpha data type for SQL), or length and precision (e.g. the ImpliedDecimal data type for SQL). To support this requirement CodeGen will search for and replace the following specific patterns of characters within data mapping values defined in your XML file:

Pattern of Characters

Replaced With

(l)

The length if the field in parentheses. E.g. (10)

(l.p)

The length and precision of the field, separated by a period, in parentheses. E.g. (10.2)

(l,p)

The length and precision of the field, separated by a comma, in parentheses. E.g. (10,2)

You only need to specify the parts of the XML file that correspond to the specific data mappings that you wish to change. For example, if all you want to do is make the <FIELD_CSTYPE> token insert the TimeSpan data type for D8 and D6 date fields (YYYYMMDD and YYMMDD) then you would configure your data mappings file like this:

<?xml version='1.0'?>
<DataMappings>
  <CSharp>
    <TimeHHMMSS>TimeSpan</TimeHHMMSS>
    <TimeHHMM>TimeSpan</TimeHHMM>
  </CSharp>
</DataMappings>

Once you have configured your custom data mappings file you tell CodeGen to use it by using the -cdm command line option, or if you are using the CodeGenerator API via the CodeGenTaskSet.DataMappingsFile property.

 

 

 


Copyright © 2018  Synergex International, Inc.