UML elements transformed by the UML-to-C# transformation

The C# elements that the transformation transforms depends on the source UML elements and their characteristics.

The following table lists which UML elements transform into which C# elements.

UML element C# element
Model C# project
Package in the Mapping Model Folder with the same name in the C# project
Package in the model C# namespace
Package in the model with «analysis» or «Analysis» keyword Ignored
Attribute C# field
Attribute with «CSharp Field» C# field
Attribute with «CSharp Event» stereotype C# event

Sterotype «CSharp Event» has a boolean property accessors indicating whether or not the event has the accessors (add and remove) specified. A true value indicates that add and remove accessors are explicitly specified and a false indicated the event accessors are implicit.

Attribute with «CSharp Property» stereotype C# property class member, with field_name attribute of type String.
Attribute with «CSharp Property» stereotype and accessors property of the stereotype set to auto C# automatically implemented property

The property class member contains both get and set accessors, without a body block.

Class C# class with the same name and visibility
Class with «CSharp Delegate» stereotype C# delegate

The invocation method and its signature are mapped using the UML operation within the UML class. The name of this operation should be “invoke()”.

Class with «CSharp Struct» stereotype C# structure
Two classes with a dependency relationship between them with the «CSharp Partial» stereotype C# partial classes
Class with two or more dependent classes; dependency relationships to the first class have the «CSharp Partial» stereotype. An operation exists in each dependent class with the same name, one with «CSharpPartialDeclaration» stereotype and one with «CSharp PartialDefinition» stereotype C# partial methods

A class with two partial implementations is created. The partial part containing the operation with the «CSharpPartialDeclaration» stereotype will have the method declaration without the method body. The partial part containing the operation with the «CSharpPartialDefinition» will have the method and its body.

Class with generalization relationship C# class extends the specified superclass
Implementation C# class implements the specified interface
Realization relationship between a Class and an Interface C# class implements the specified interface, including template interfaces. The transformation generates code for methods, properties, events, and indexers in the class from the implemented interface
Interface C# interface with the same name and visibility
Interface with generalization relationship C# interface extends the specified interface
Enumeration C# enumeration of the same name with the default underlying type of "int" and with none of the Enumeration members having a constant expression
Enumeration literal C# field with the same name and visibility
Operation C# method with the same name and visibility
Operation with "implicit/explicit operator" or "operator" and symbol in name C# operator
The name of the operation is one of the following:
  • operator unary_or_binary_operator_symbol for a unary or binary operation definition. The return type of such an operation is the type of result return by unary/binary operator.
  • implicit operator or explicit operator for an implicit or explicit operator. The return type of such an operation will be the target type of conversion. The source type for conversion will be the UML Parameter type
Operation with isStatic property C# method is static if true
Operation with isAbstract property C# method is abstract if true
Operation with isVirtual property C# method is virtual if true
Operation with the same name as its class C# constructor
Operation with "~" and the same name as its class C# destructor
Operation with «CSharp Indexer» stereotype C# indexer

The formal parameter list for an indexer is represented as formal parameters of the UML operation.

Operation with isStatic property and «CSharp ExtensionMethod» stereotype

The operation must be a member of a class with «CSharp Class» stereotype and the static property of the stereotype set to True

C# extension method

A modifier called this is applied to the first parameter of the operation.

Types Boolean, Integer, String, and UnlimitedNatural Types Boolean, Int32, String, and UInt32
Note:

UML packages in a model with names containing periods 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 folder, 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

Feedback