C# Extension for StarUML
This extension for StarUML(http://staruml.io) support to generate C# code from UML model and to reverse C# code to UML model. Install this extension from Extension Manager of StarUML.
Note This extensions do 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.
Note This extension is based on C# 2.0 specification.
C# Code Generation
- Click the menu (
Tools > C# > Generate Code...) - Select a base model (or package) that will be generated to C#.
- Select a folder where generated C# source files will be placed.
Belows are the rules to convert from UML model elements to C# source codes.
UMLPackage
- converted to C# namespace (as a folder).
UMLClass
- converted to C# Class. (as a separate
.csfile) visibilityto one of modifierspublic,protected,privateand none.isAbstractproperty toabstractmodifier.isFinalSpecializationandisLeafproperty tosealedmodifier.- 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)
UMLAttribute
- converted to C# Field.
visibilityproperty to one of modifierspublic,protected,privateand none.nameproperty to field identifier.typeproperty to field type.multiplicityproperty to array type.isStaticproperty tostaticmodifier.isLeafproperty tosealedmodifier.defaultValueproperty to initial value.- Documentation property to C#Doc comment.
UMLOperation
- converted to C# Methods.
visibilityproperty to one of modifierspublic,protected,privateand none.nameproperty to method identifier.isAbstractproperty toabstractmodifier.isStaticproperty tostaticmodifier.- UMLParameter to C# Method Parameters.
- UMLParameter's name property to parameter identifier.
- UMLParameter's type property to type of parameter.
- UMLParameter with
direction=returnto return type of method. When no return parameter,voidis used. - UMLParameter with
isReadOnly=truetosealedmodifier of parameter. - Documentation property to C#Doc comment.
- If
stereotype=propertythen converted to C# Property. - With
isReadOnlyjust the getter is generated.
UMLInterface
- converted to C# Interface. (as a separate
.csfile) visibilityproperty to one of modifierspublic,protected,privateand none.- Documentation property to C#Doc comment.
UMLEnumeration
- converted to C# enum. (as a separate
.csfile) visibilityproperty to one of modifierspublic,protected,privateand none.- UMLEnumerationLiteral to literals of enum.
UMLAssociationEnd
- converted to C# Field.
visibilityproperty to one of modifierspublic,protected,privateand none.nameproperty to field identifier.typeproperty to field type.- If
multiplicityis one of0..*,1..*,*, then collection type (List<>whenisOrdered=trueorHashSet<>) is used. defaultValueproperty 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
- Click the menu (
Tools > C# > Reverse Code...) - Select a folder containing C# source files to be converted to UML model elements.
CsharpReversemodel will be created in the Project.
Belows 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
nameproperty. - Type parameters to UMLTemplateParameter.
- Access modifier
public,protectedandprivatetovisibilityproperty. abstractmodifier toisAbstractproperty.sealedmodifier toisLeafproperty.- 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
typeproperty.- Primitive Types :
typeproperty has the primitive type name as string. T[](array) or its decendants:typeproperty refers toTwith multiplicity*.T(User-Defined Types) :typeproperty refers to theTtype.- Otherwise :
typeproperty has the type name as string.
- Primitive Types :
-
Access modifier
public,protectedandprivatetovisibilityproperty. -
staticmodifier toisStaticproperty. -
sealedmodifier toisLeafandisReadOnlyproperty. -
Initial value to
defaultValueproperty.
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) correspond to the field type.
-
Field type to
end2.referenceproperty.T[](array) or its decendants:referenceproperty refers toTwith multiplicity*.T(User-Defined Types) :referenceproperty refers to theTtype.- Otherwise : converted to UMLAttribute, not UMLAssociation.
-
Access modifier
public,protectedandprivatetovisibilityproperty.
C# Method
- converted to UMLOperation.
- Type parameters to UMLTemplateParameter.
- Access modifier
public,protectedandprivatetovisibilityproperty. staticmodifier toisStaticproperty.abstractmodifier toisAbstractproperty.sealedmodifier toisLeafproperty.
C# Interface
- converted to UMLInterface.
- Class name to
nameproperty. - Type parameters to UMLTemplateParameter.
- Access modifier
public,protectedandprivatetovisibilityproperty.
C# Enum
- converted to UMLEnumeration.
- Enum name to
nameproperty. - Type parameters to UMLTemplateParameter.
- Access modifier
public,protectedandprivatetovisibilityproperty. - 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).