Data Types
Data Types solve one of the biggest issues in Code Generation, which is how to resolve each code base having a different presentation of primitive types. In C# a Double, Int, Float, Int32 are all a Number in JavaScript and a Date in C# is a Date object in JavaScript and a string in HTML!
To help work around this issue in SilverModel you create all your primitive Data Types, then to these primitive Data Types you assign a computer language, then to the computer language you assign what type in will be in that language. Then during code generation you can lookup which data type is required for the language you are currently generating code for. e.g to get the data type for C# use @att.Type.TypeName("C#")
All Code Generator can have their own Data Types, by default it is recommend to use only the "DataTypes" code generator for storing all your data types. All the Code Generators can access and share these Data Types.
Data Type Code Generator
There is already an number of different Data Types mapped in SilverModel, these are in the "DataTypes" code generator.
By default the "DataTypes" code generator is automatically assigned to all new UML Class Diagrams. This allows your UML Class Diagrams to start with a base set of Data Types.
Example From Data Types Code Generator
In this example we can see the "DateTime" Data Type has been added to the DataTypes Code Generator
Then the computer languages C#, TypeScript and HtmlInput have been added.
Then to the computer languages , the Language Data Types have been added.
So when we request the Code Generator for the what is the data type for DateTime in Typescript, the system will be able to return "string"
Language Data Type Properties
Each Language Data Type has three properties
- Init
- New
- Type
Init Property
This allows you to have a default initialization for your Language Data Types. e.g for a double in C#, the init property could be set to 0. Which would allow the following code to be generated
double myDouble=0;
The Code Generators could then insert the init value as required.
New Property
This allow you to define now a new instance of the Language Data Type will be defined. e.g for a DateTime in C#, the new could be set to DateTime.Now().
DateTime myDate=DateTime.Now();
The Code Generators could then insert the new value as required.
Type Property
This allows you to defines which type the computer language could use for a Data Type.e.g for a double in C#, the Type property could be set to double. Which would allow the following code to be generated
double myDouble=0;
Example
The defaults properties for C# DateTime
Using Data Types in Code Generators
The Language Data Type Name can be accessed via the Type property of the Property e.g.
att2.Type.TypeName("C#")
The Language Data Type New string can be accessed via the Type property of the Property e.g.
att2.Type.TypeNew("C#")
The Language Data Type Init string can be accessed via the Type property of the Property e.g.
att2.Type.TypeInit("C#")