Association and role mapping for C# (C# code)
ACS generates Roles applied by Associations and Aggregations as constants, fields or properties of a class, struct or interface. The type of the constant, field or property is the class, struct or interface that is generated for the Class that is linked through the Association or Aggregation.
|
If you want the type of a constant, field or property to not be a class, struct or interface; model the constant, field or property through an Attribute. For more information about Attribute, mapping, click here
Attribute mapping.
|
The following class and struct members can be generated:
• Constants – apply the «C# Constant» stereotype to the Role.
• Fields – apply the «C# Field» stereotype to the Role.
• Properties – apply the «C# Property» stereotype to the Role.
The following interface members can be generated:
• Properties – apply the «C# Property» stereotype to the Role.
If none of the preceding Stereotypes are applied to the Role, ACS generates the Role as a field.
The code file in which the members are created is determined by the Association Type:
• Start-end - generated in the code file created for the Start item.
• End-start - generated in the code file created for the End item.
• Bi-directional - generated in the code files created for both the Start item and End item.
• None - the Association is ignored.
ACS generates the child items, properties and tagged values of a Role as follows.
Child items:
• A Role does not have any child items that are generated.
Properties:
• The Behavior property is ignored.
• The Composite property is ignored.
• The Data Type is the associated Class; ACS generates the value as the class member's type, unless a delegate is specified through the C# Delegate Type tag definition.
• If the Default Value property is set, ACS generates the value as the default value of the class member when appropriate.
• ACS generates the Multiplicity property as follows:
◦ if zero or one – ACS generates the Data Type with a '?' type modifier (as a nullable type).
◦ if only one – ACS generates the Data Type as is.
◦ if zero or more – ACS generates a 'using System.Collections;' statement, and 'ArrayList' for the type.
◦ if one or more – ACS generates a 'using System.Collections;' statement, and 'ArrayList' for the type.
◦ if tbd – ACS ignores the Role.
◦ if user defined – the value determines how ACS generates the code: If the user defined value matches one of the preceding values (such as zero or one), ACS generates it accordingly. If the value is an integer value that is greater than 1, ACS generates the Data Type followed by '[]'. If the value is none of the preceding, ACS generates the Data Type as is, followed by the user defined value.
• ACS generates the Name property as the identifier of the class member in the code. If no name is specified for the Role, the name of the associated Class is used.
| Note that ACS may modify the Role name that is added to the code to make it valid for C#. You can specify the exact Role name to add to the code through the CODE_GENERATION_NAME property of a Role.
Tell me more... |
• The Port property is ignored.
• If the Read Only property is set to true (Read Only check box selected on Property Pages), ACS generates the class member with the readonly modifier when appropriate (Role maps to a C# field).
• The Qualifier property is ignored.
• If the Storage property is set to On Class, ACS generates the member with the static modifier.
• The Unique property is ignored.
• The Visibility property is used to generate a Role with the correct visibility in the class definition:
◦ If the Visibility is set to Public, Protected or Private, ACS generates Roles with either a public, protected or private modifier.
◦ If the Visibility is set to Package, the Role is treated as an internal.
◦ If the tagged value of the C# Internal tag definition is set to internal or protected internal, the Visibility property is ignored.
Tag Definitions:
For Constants
If the «C# Constant» stereotype is applied to the Role, ACS generates the Role as a constant. When you set up a Role as a constant, set the Read Only property to True (Read Only check box on the Property Pages), else a warning message will be generated. The «C# Constant» stereotype applies the following tag definitions to a Role:
• If the type of the constant is a generic type, ACS generates the tagged value of the C# Actual Parameters tag definition as the type arguments for that generic type.
• If a value is set for the tagged value of the C# Attributes tag definition, ACS generates the value as the attributes of the constant.
• If the tagged value of the C# Delegate Type tag definition references an Operation, ACS generates the value as type of the constant.
• If the tagged value of the C# Internal tag definition is set to Internal, ACS generates the constant with the internal modifier. If a value of the C# Internal tag definition is set to Protected Internal, ACS generates the constant with the protected internal modifiers.
• If the tagged value of the C# Needs Qualified Type tag definition is set to True, ACS generates the constant's type using its fully qualified name, rather than its unqualified name.
• If the tagged value of the C# New tag definition is set to True, ACS generates the new keyword when appropriate.
For Fields
If the «C# Field» stereotype is applied to a Role, ACS generates the Role as a field. The «C# Field» stereotype applies the following Tag Definitions to a Role:
• If the type of the field is a generic type, ACS generates the tagged value of the C# Actual Parameters tag definition as the type arguments for that generic type.
• If a value is set for the tagged value of the C# Attributes tag definition, ACS generates the value as the attributes of the field.
• If the tagged value of the C# Delegate Type tag definition references an Operation, ACS generates the value as type of the field.
• If the tagged value of the C# Internal tag definition is set to Internal, ACS generates the field with the internal modifier. If a value of the C# Internal tag definition is set to Protected Internal, ACS generates the field with the protected internal modifiers.
• If the tagged value of the C# Needs Qualified Type tag definition is set to True, ACS generates the field's type using its fully qualified name, rather than its unqualified name.
• If the tagged value of the C# New tag definition is set to True, ACS generates the new keyword when appropriate.
• The C# Read Only tag definition is not used at present. Use the Modeler Read Only property to generate the Read only modifier.
• If the tagged value of the C# Unsafe tag definition is set to True, ACS generates the field with the Unsafe modifier.
• If the tagged value of the C# Volatile tag definition is set to True, ACS generates the field with the Volatile modifier.
For Properties
If the «C# Property» stereotype is applied to a Role, ACS generates the Role as a property member. The «C# Property» stereotype applies the following Tag Definitions to a Role:
| ACS generates a property only after a tagged value is set for either the C# Get Accessor Body or C# Set Accessor Body tag definition. |
• If the tagged value of the C# Abstract tag definition is set to True (and the Role is not virtual, sealed or extern, and has on instance Storage), ACS generates the property member with the abstract modifier, assuming that the owning item is abstract.
• If the associated item is a generic type, ACS generates the tagged value of the C# Actual Parameters tag definition as the type arguments for that generic type.
• If a value is set for the tagged value of the C# Attributes tag definition, ACS generates the value as the attributes of the property member.
• If the tagged value of the C# Delegate Type tag definition references an Operation, ACS generates the value as type of the property.
• If the tagged value of the C# Extern tag definition is set to True (and the Role is not abstract), ACS generates the property member with the extern modifier.
• If a value is set for the tagged value of the C# Get Accessor Attributes tag definition, ACS generates the value on the line before the Get statement as the attributes of the get accessor declaration.
• If a value is set for the tagged value of the C# Get Accessor Body tag definition, ACS generates the value as the body code of the get accessor declaration.
If reverse engineering is enabled in ACS, you can change the body code of the get accessor in the code file and ACS will update the tagged value of the C# Get Accessor Body tag definition in the model.
• If the value of the C# Get Accessor Modifierstag definition is not set to none, ACS generates the value as the modifiers of the get accessor declaration.
• If the tagged value of the C# Internal tag definition is set to Internal, ACS generates the property member with the internal modifier. If a value of the C# Internal tag definition is set to Protected Internal, ACS generates the property member with the protected internal modifiers.
• If the tagged value of the C# Needs Qualified Type tag definition is set to True, ACS generates the property's type using its fully qualified name, rather than its unqualified name.
• If the tagged value of the C# New tag definition is set to True, ACS generates the new keyword when appropriate.
• If the tagged value of the C# Override tag definition is set to True (and the Role is virtual with on instance storage), ACS generates the property member with the override modifier.
• If the tagged value of the C# Sealed tag definition is set to True (and the Role is virtual with on instance storage), ACS generates the property member with the sealed modifier.
• If a value is set for the tagged value of the C# Set Accessor Attributes tag definition, ACS generates the value on the line before the Set statement as the attributes of the set accessor declaration.
• If a value is set for the tagged value of the C# Set Accessor Body tag definition, ACS generates the value as the body code of the set accessor declaration.
If reverse engineering is enabled in ACS, you can change the body code of the set accessor in the code file and ACS will update the tagged value of the C# Set Accessor Body tag definition in the model.
• If the value of the C# Set Accessor Modifierstag definition is not set to none, ACS generates the value as the modifiers of the set accessor declaration.
• If the tagged value of the C# Unsafetag definition is set to True, ACS generates the property member with the Unsafe modifier.
• If the tagged value of the C# Virtualtag definition is set to True (and the Role is not abstract or override, and has on instance storage), ACS generates the property member with the virtual modifier.