You can specify the model elements that the transformation should convert to C# code when you create or edit a transformation configuration. The transformation generates an error message if you select both a container and its model elements or the same model element twice.
Names for UML source elements can begin with a lowercase letter, uppercase letter, or an underscore (_). The subsequent characters can be lowercase letters, uppercase letters, or numbers. The transformation prefixes a name that begins with a number or an invalid character with an underscore (_).
To improve the readability of the generated code and to minimize the differences between the UML model and generated code, you should correct invalid names in the source UML model before you apply the transformation.
A valid transformation target is an imported Visual Studio C# project. If you create a new target container, you initiate a .NET solution import. The .NET solution must be open in Visual Studio to be imported.
The following table lists how the UML-to-C# transformation transforms UML model elements into C# code. Some UML elements can be transformed into multiple code elements with the correct stereotype applied.
| UML model element | C# code element |
|---|---|
| Association relationship | Class attribute |
| Class | Class, structure, or delegate |
| Enumeration | Enum |
| Generalization relationship | Class inheritance |
| Operation | Method or indexer |
| Package | Namespace |
| Parameter | Method argument |
| Property | Class attribute, C# property, or event |
UML packages in a UML model with names containing periods or spaces are transformed into C# namespaces with names containing underscores. This transformation behavior preserves a single namespace for the contained elements. For example, suppose a UML package, com.ibm.samples, contains a class named C1. After applying the UML-to-C# transformation, a C# artifact representing the UML class C1 is declared in the following namespace:
namespace com_ibm_samples
In instances where you want to create three namespaces, you must create three separate packages in the UML model, for example: com, ibm and samples. In this case, com is the parent folder containing the ibm folder, and ibm contains the samples folder. The result after transformation is a series of nested namespaces in the code.
The mapping model can be used to generate folders from UML packages and to control the output of classes and other artifacts. For example, you can use the mapping model to generate multiple C# classes into a single file.
The transformation generates C# code files in the C# projects and C# project folders that you specify as the target of the transformation.
The transformation provides integration functionality with IBM® Rational® Team Concert, CVS, Rational ClearCase®, and Rational ClearCase LT version control systems, which enables you to automatically check out files or add new files. You must enable team capabilities to work with configuration management systems.