Modeling C# automatically implemented properties

This content applies to version 7.5.2 or later. You can model C# 3.0 automatically implemented properties to generate code. Properties in the code can also be generated in the model using a C#-to-UML transformation.

Before you begin

To use the stereotypes required in this procedure, you must apply the C# transformation profile to the model.

About this task

To create automatically implemented properties in the model:

Procedure

  1. In the Project Explorer view or diagram editor, right-click a UML class; then click Add UML > Attribute.
  2. Click the Stereotype tab.
  3. Click Apply Stereotypes, select CSharp Property, and then click OK.
  4. Under Stereotype Properties, set accessors to auto.

Example

The following image shows a UML class, AClass, containing the automatically implemented property, AnAutoProperty.
Diagram view of an automatically implemented property.

After a UML-to-C# transformation is run, the following code is generated:

//Begin section for file AClass.cs
//TODO: Add using directives that you want preserved
//End section for file AClass.cs
using System;

// @generated
public class AClass
{
	// @generated
	private Object AnAutoProperty
	{
		get;
		set;
	}
}

The C# property AnAutoProperty can be used in the C# code just like an explicitly implemented property.

What to do next

After modeling the automatically implemented property, you can configure and run a UML-to-C# transformation to generate the C# code.

Feedback