StereoTypes(Custom Attributes) For Code Generators
A lot of development languages(e.g C#, Java) allow you to add custom attributes(metadata) to them
For example
[DataMember]
[Browsable(false)]
public DateTime DateCreated { get; set; }=DateTime.Now;
UML calls this feature Stereotypes and it allows you to extend the UML models with metadata. So for example you could add an stereotype(attribute) for a regex expression to enable data valuation.
This is a very powerful feature that allows you to extend via metadata what the object is capable of. For example you could add attributes to enable serialization.
The Code Generators can then access these Stereotypes to enable advanced functionality in the generated code.
With a code generation there are three elements you can add an SteropType at
- Model (Diagram)
- Classifier (Class or Interface)
- Property (Attribute)
Stereotype Propertys
When you add a Stereotype to one of these above elements, you can set the following property's
- Group
- Name
- Type
- Value
Group
The group property defines which property group the stereotype will appear in the elements property window.
Name
The name property defines the name for the property in the properties window
Type
Defines the type the user will enter in the properties window.
The type can be one of the following
- Boolean
- Datatype
- Date
- Directory
- File
- GUID
- LongNote
- LocalElement
- LocalClass
- PropertyType
- RichNote
- String
- UmlClass
- UmlElement
- UmlModel
- Variable
Boolean
Allow the user to enter a yes/no value
DataType
Allow the user to select a primitive data-type as defined in the code generators e.g. integer
Date
Allow the user to enter a date
Directory
Allows the user to choose an Directory. e.g. Where the code will be output to.
File
A file in the filesystem
LongNote
An extra field for documentation
Local Element
Local Class
Property Type
RichNote
An extra field for documentation in the rich text format
String
A string value
UML Class
An UML Class selected from the current project
UML Model
An UML Model selected from the current project
UML Element
An UML Element selected from the current project
Variable
Value
This allow the code generator to set a default value for any new Stereotype.
Example
The Entity Framework has a number of stereotypes. One at the Model Level to define what the DBContext will be and two at the property level.
The DBContextName Stereotype was the following property values.
And when this Code Generator is assigned to a project, the below stereotype is added to the Model.