Fine-tuning code generated for return types

You can use the Code pattern field to fine-tune the code that is generated for the return type of a specific operation. If you want to modify the code that is generated when a given class, type, or event is used as the return type of an operation anywhere in your model, you can set the value of the ReturnType property at the class, type, or event level.

You can fine-tune the code that is generated for the return type of an operation at two different levels:

  • at the operation level, by specifying the code that should be generated for the return type of a specific operation
  • at the project level, by specifying the code that should be generated any time a specific class (or type or event) is used as the return type of an operation

Code generated for the return type of a specific operation

To specify the code that should be generated for the return type of a specific operation, modify the content of the Code pattern field on the General tab of the Features window for the operation. This content can consist of actual C/C++ code together with the $type keyword, which will generate the type of the model element that is being used for the return type, for example, you can enter $type**

When you modify the content of the Code pattern field and then press Apply, you can see the change immediately in the operation signature that is displayed on the General tab of the Feature dialog for operations.

The Code pattern field corresponds to the ReturnType property. After you modify the contents of the field and press Apply, you can see the change reflected in the value of the relevant ReturnType property at the argument level.

For example:

  • If you modified the code pattern for a return type that is a class, you will see the new value under [lang]_CG::Class::ReturnType.
  • If you modified the code pattern for a return type that is an event, you will see the new value under [lang]_CG::Event::ReturnType.

The relationship with the property is two-way. In theory, you can also modify the value of the relevant ReturnType property at the argument level, and you will see the new value reflected in the Code patternfield. However, since this is only for the context of a single operation, there is no advantage of using the property rather than modifying the Code pattern field directly.

Code generated when a given class, type, or event is used as a return type anywhere in the model

If you want to modify the code that is generated when a given class, type, or event is used as the return type of an operation anywhere in your model, you can set the value of the relevant ReturnType property for the relevant class, type, or event.

For example:

  • If you modify the value of the property [lang]_CG::Class::ReturnType for a class called Printer, this will affect the code that is generated anywhere that a return type of type Printer is used as the return type of an operation in your model.
  • If you modify the value of the property [lang]_CG::Type::ReturnType for a Type called Color, this will affect the code that is generated anywhere that a return type of type Color is used as the return type of an operation in your model.
Note: If you set the value of the ReturnType property at the level of a class, type, or event, you can still override the code generation pattern in the context of an individual operation by entering a different code pattern in the Code pattern field for the return type, or by overriding the value of the property at the operation level.