-
Notifications
You must be signed in to change notification settings - Fork 6
UML Code Generation ‐ Convention
All classes produce a C# interface, only concrete classes produce a C# class.
Since the UML classes can have multiple Generalization, the C# inheritance is done only via interfaces.
The following Data Type can be found into the UML model:
- Boolean: translates to C# bool
- UnlimitedNatural: translates to C# string
- String: translates to C# string
- Integer: translates to C# int
- Real: translates to C# double
- Enumeration: translate to correspondant C# enum
Translates to a reference to the Interface definition of the specified type
Translates to a Guid
- [0..1]: Translates to nullable (Except for string, which is nullable by definition)
- [1..]/[n..]: Translates to List{T}
- [0..1]: Not a nullable since a reference type is nullable by definition
- [1..*]/[n..*]: Translates to List{T}
- [0..1]: Translates to
Guid? - [1..*]/[n..*]: Translates to List{Guid}
For all non-derived properties, property name starts with an uppercase.
For all derived properties, property name starts with a lowercase.
When a property has been redefined on the current context, this property has to be discarded by the class since it does not have any meaning due to the redefinition of it. To discard it, we declares it with an explicit interface definition.
- Nominal Case: translates to
{ get; set; } - ReadOnly: translates to
{ get; } - Derived or DerivedUnion: Translates to
=> this.Compute$PROPERTYNAME$();. This method is hand-coded to implement derive-computation logic
- Nominal Case: translates to
{ get; set; } - ReadOnly: translates to
{ get; } - Derived or DerivedUnion: translates to
{ get; }on interface definition,{ get; internal set; }on class implementation
Not implemented for now
To make sure that no exception or incorrect values are thrown in case of interface usage (like a collection of super interface), it is important to be able to not throw exception or irrelevant values. To make it possible, getter and setter have to return/set values of the property that redefines it.
Following section explains implementation principle. Each case are explain in terms of multiplicity, where the first multiplicity is the one of the redefined property and the second one is for the redefinition
- [n..*] -> [n..*] : Returns a newly initialized collection to allow safe cast and to not allow direct modification of the redefinition collection via a redefined property
- [n..*] -> [1..1] : Returns a newly initialized collection that contains only one element, the value of the redefinition
- [n..*] -> [0..1] : Returns a newly initialized collection that contains only zero element if the value of the redefinition is null, one otherwise
- [1..1] -> [1..1]/[0..1] -> [0..1] : Returns the value for the redefinition one
- [1..1] -> [0..1] : Returns the value of the redefinition if not null, the default value otherwise
If the redefinition is a derived property, the setter does not do anything
- [n..*] -> [n..*] : Assigns the collection to the redefinition. For POCO, gets only elements of the correct type
- [n..*] -> [0/1..1] : Assigns the value based on the first value of the collection. For POCO, based on the first value of the collection that matches the target type
- [0/1..1] -> [0/1..1] : Assigns the value if type matches the target one.
- Property name follows the CamelCase format
- @type (string) property required (value is the name of the serialized)
- @id (uuid) property (optional)
- Boolean: translates to json bool
- UnlimitedNatural: translates to json string
- String: translates to json string
- Integer: translates to json numeric
- Real: translates to json numeric
- Enumeration: translate to full lowercase string
A refence is represented through a JSON object which that contains one property @id with the value of the reference Guid
- [0..1]: Always serialized, null in case of null, the value otherwise
- [1..*]/[n..*]: Serialized through a JSON array
The serialization of derived property is possible. Deserialization action can also assign derived properties into DTOs if present inside the JSON payload.
Redefined property are discarded from the serialization.
copyright @ Starion Group S.A.