-
Notifications
You must be signed in to change notification settings - Fork 3
Code Generation
The SysML2.NET libraries are generated from the SysML.ecore ECore metamodel. We make use of convention and template based code generation to convert the information that is stored in the ECore model to various C# classes such as DTO's, POCO's, JSON serializers and much more. The Starion Group EcoreNetto library is used to read the Ecore model. Handlebars templates are used to generate code using the Handlebars.Net library.
The code-generators are executed from the Unit test project called SysML2.NET.CodeGenerator.Tests
. The generated code is verified (compared) against so-called expected
classes. These are hand-coded and are used to implement a pattern that needs to be generated. An analysis of the SysML2 Ecore model has been performed to check that all the variations in data-types, multiplicity, inheritance etc. is covered. A number of classes have been selected for which expected
classes need to be in place such that the generated code is properly covered. The following lists provides an overview of the various kinds of features which classes cover these features, hence which class needs to be included in the expected
classes:
The following Value Type Feature can be found in the ECore model:
- Boolean [1..1] : translates to C# bool
- Integer [1..1] : translates to C# int
- Real [1..1] : translates to C# double
- String [1..1] : translates to C# string
- String [0..1] : translates to C# string? (nullable)
- String [0..*] : translates to C# List
- Enum [0..1] : translates to C# Enum? (nullable)
- Enum [1..1] : translates to C# Enum
The following Reference Type Feature multiplicities can be found in the ECore model:
- [0..1] : POCO translates to
reference
of specified type | DTO translates to aGuid?
(nullable) - [1..1] : POCO translates to
reference
of specified type | DTO translates to aGuid
- [0..*] : POCO translates to
List<reference>
of specified type | DTO translates to aList<Guid>
- [1..*] : POCO translates to
List<reference>
of specified type | DTO translates to aList<Guid>
The following containment (composite aggregation) Reference Type Feature multiplicities can be found in the ECore model:
- [0..*] : POCO translates to
List<reference>
of specified type | DTO translates to aList<Guid>
These variations are covered by the following classes:
- AnnotatingElement
- Annotation
- Comment
- Connector
- Dependency
- Element (abstract)
- Feature
- Import (abstract) / NamespaceImport (concrete)
- LiteralInteger
- LiteralRational
NOTE: The ModelInspector class is used to perform the beforementioned analysis of pattern variation.
The following code-generators are present:
- HtmlDocsGenerator: generates HTML documentation
- CoreEnumGenerator: generates enum C# files
- CoreDtoGenerator: generates partial DTO C# class files
- CorePocoGenerator: generates partial POCO C# class files
- CoreDalPocoExtensionsGenerator: Generates static POCO extions used to derefernce the object graph based on DTO's
- CoreJsonDtoDeSerializerGenerator: generates JSON deserializer C# class files
- CoreJsonDtoSerializerGenerator: generates JSON serializer C# class files
- CoreDtoDictionaryReaderGenerator: generates Dictionary<string, Object> Reader C# class files
- CoreDtoDictionaryWriterGenerator: generates Dictionary<string, Object> Writer C# class files
NOTE: the structure of a code-generator is described here.
copyright @ Starion Group S.A.