-
Notifications
You must be signed in to change notification settings - Fork 3
Primitive Types Mapping
In UML a modeller can make use of the existing Primitive Types, typically included in the PrimitiveTypes.xmi model. These standard Primitive Types are mapped to types in C# in the TypeExtensions class. The following mapping is included with uml4net:
| UML Primitive Type | C# Type |
|---|---|
| Boolean | bool |
| Integer | int |
| Real | double |
| String | string |
| UnlimitedNatural | string |
By calling the TypeExtensions.QueryCSharpTypeName method, the above mapping is used.
In case a UML model contains more Primitive Types, the mapping can be updated to support this. Let's state that a UML model contains a Primitive Type called ISO8601DateTime that needs to be mapped to the equivalent in C# DateTime.
This can be achieved by called the static method PropertyExtensions.AddOrOverwriteCSharpTypeMappings method before any code generation is performed
Extensions.PropertyExtensions.AddOrOverwriteCSharpTypeMappings(("ISO8601DateTime", "DateTime"));
In case an existing mapping needs to be overwritten that can be achieved with the same method. The following example demonstrates how the existing default mapping Real -> double is overwritten to become Real -> float.
Extensions.PropertyExtensions.AddOrOverwriteCSharpTypeMappings(("Real", "float"));
copyright @ Starion Group S.A.