Navigation Menu

Skip to content

staruml/staruml-csharp

Repository files navigation

C# Extension for StarUML

This extension for StarUML supports C# code generation from a UML model. It also allows converting C# code into a UML model. Install this extension from Extension Manager of StarUML.

⚠️ This extension does not provide perfect reverse engineering, which is a test and temporal feature. If you need a complete reverse engineering feature, please check other professional reverse engineering tools.

✅ This extension is based on C# 2.0 specification.

C# Code Generation

  1. Click the menu (Tools > C# > Generate Code...)
  2. Select a base model (or package) that will be generated to C#.
  3. Select a folder where generated C# source files will be placed.

Below are the rules to convert UML model elements to C# source code.

UMLPackage

  • converted to C# namespace (as a folder).

UMLClass

  • converted to C# Class. (as a separate .cs file)
  • visibility to one of modifiers public, protected, private and none.
  • isAbstract property to abstract modifier.
  • isFinalSpecialization and isLeaf property to sealed modifier.
  • Default constructor is generated.
  • All contained types (UMLClass, UMLInterface, UMLEnumeration) are generated as inner type definition.
  • Documentation property to C#Doc comment.
  • Annotation Type is converted to C# attribute class, which extends System.Attribute and postfix of class is Attribute. (cf. class testAttribute:System.Attribute)
  • If stereotype = struct then converted to C# Struct.

UMLAttribute

  • converted to C# Field.
  • visibility property to one of modifiers public, protected, private and none.
  • name property to field identifier.
  • type property to field type.
  • multiplicity property to array type.
  • isStatic property to static modifier.
  • isLeaf property to sealed modifier.
  • defaultValue property to initial value.
  • Documentation property to C#Doc comment.

UMLOperation

  • converted to C# Methods.
  • visibility property to one of modifiers public, protected, private and none.
  • name property to method identifier.
  • isAbstract property to abstract modifier.
  • isStatic property to static modifier.
  • UMLParameter to C# Method Parameters.
  • UMLParameter's name property to parameter identifier.
  • UMLParameter's type property to type of parameter.
  • UMLParameter with direction = return to return type of method. When no return parameter, void is used.
  • UMLParameter with isReadOnly = true to sealed modifier of parameter.
  • Documentation property to C#Doc comment.
  • If stereotype = property then converted to C# Property.
  • With isReadOnly just the getter is generated.

UMLInterface

  • converted to C# Interface. (as a separate .cs file)
  • visibility property to one of modifiers public, protected, private and none.
  • Documentation property to C#Doc comment.

UMLEnumeration

  • converted to C# enum. (as a separate .cs file)
  • visibility property to one of modifiers public, protected, private and none.
  • UMLEnumerationLiteral to literals of enum.

UMLAssociationEnd

  • converted to C# Field.
  • visibility property to one of modifiers public, protected, private and none.
  • name property to field identifier.
  • type property to field type.
  • If multiplicity is one of 0..*, 1..*, *, then collection type (List<> when isOrdered = true or HashSet<>) is used.
  • defaultValue property to initial value.

UMLGeneralization

  • converted to C# Extends (:).
  • Allowed only for UMLClass to UMLClass, and UMLInterface to UMLInterface.

UMLInterfaceRealization

  • converted to C# Implements (:).
  • Allowed only for UMLClass to UMLInterface.

C# Reverse Engineering

  1. Click the menu (Tools > C# > Reverse Code...)
  2. Select a folder containing C# source files to be converted to UML model elements.
  3. CsharpReverse model will be created in the Project.

Below are the rules to convert from C# source code to UML model elements.

C# Namespace

  • converted to UMLPackage.

C# Class

  • converted to UMLClass.
  • Class name to name property.
  • Type parameters to UMLTemplateParameter.
  • Access modifier public, protected and private to visibility property.
  • abstract modifier to isAbstract property.
  • sealed modifier to isLeaf property.
  • Constructors to UMLOperation with stereotype <<constructor>>.
  • All contained types (UMLClass, UMLInterface, UMLEnumeration) are generated as inner type definition.

C# Field (to UMLAttribute)

  • converted to UMLAttribute if "Use Association" is off in Preferences.

  • Field type to type property.

    • Primitive Types : type property has the primitive type name as string.
    • T[](array) or its descendants: type property refers to T with multiplicity *.
    • T (User-Defined Types) : type property refers to the T type.
    • Otherwise : type property has the type name as string.
  • Access modifier public, protected and private to visibility property.

  • static modifier to isStatic property.

  • sealed modifier to isLeaf and isReadOnly property.

  • Initial value to defaultValue property.

C# Field (to UMLAssociation)

  • converted to (Directed) UMLAssociation if "Use Association" is on in Preferences and there is a UML type element (UMLClass, UMLInterface, or UMLEnumeration) that corresponds to the field type.

  • Field type to end2.reference property.

    • T[](array) or its descendants: reference property refers to T with multiplicity *.
    • T (User-Defined Types) : reference property refers to the T type.
    • Otherwise : converted to UMLAttribute, not UMLAssociation.
  • Access modifier public, protected and private to visibility property.

C# Method

  • converted to UMLOperation.
  • Type parameters to UMLTemplateParameter.
  • Access modifier public, protected and private to visibility property.
  • static modifier to isStatic property.
  • abstract modifier to isAbstract property.
  • sealed modifier to isLeaf property.

C# Interface

  • converted to UMLInterface.
  • Class name to name property.
  • Type parameters to UMLTemplateParameter.
  • Access modifier public, protected and private to visibility property.

C# Enum

  • converted to UMLEnumeration.
  • Enum name to name property.
  • Type parameters to UMLTemplateParameter.
  • Access modifier public, protected and private to visibility property.
  • Enum constants are converted to UMLEnumerationLiteral.

C# AnnotationType

  • converted to UMLClass with stereotype <<annotationType>>.
  • Annotation type elements to UMLOperation. (Default value to a Tag with name="default").

Licensed under the MIT license (see LICENSE file).