Programming with the UML API
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
The UML API of Visual Studio lets you write code to create, read, and update UML models and diagrams. To see which versions of Visual Studio support UML models, see Version support for architecture and modeling tools.
In addition to the API reference pages, the following topics describe the API.
Topic | Example types and methods described | Features described |
---|---|---|
Navigate relationships with the UML API | UML elements and their properties and associations. For example, IElement and its descendants, including: IClass, IActivity, IUseCase, IComponent, IInteraction, IModel, IPackage | In Visual Studio, UML models conform to the UML specification version 2.1.2, which can be obtained at the UML Resource Page. Each type is an interface that has the same name as the UML type, prefixed with "I". |
Create elements and relationships in UML models | IPackage.CreateClass() IClass.CreateOperation() |
Each element type has methods for creating its children. |
Display a UML model on diagrams | IShape, IDiagram IShape.Move() |
Each element in a model can be represented as a shape on a diagram. In some cases, you can create new shapes for each object. You can move, resize, color, and collapse or expand these shapes. |
Navigate the UML model | IModelStore IDiagramContext |
The Model Store stores the model. The Diagram Context gives you access to the current diagram and store. |
Link UML model updates by using transactions | ILinkedUndoContext | You can link a series of changes into one transaction. |
Define a menu command on a modeling diagram | IMenuCommand IGestureExtension ICommandExtension |
You can extend a diagram's functionality by defining commands invoked by double-clicking and by dragging onto the diagram. |
Define validation constraints for UML models | ValidationContext | You can define validation rules that help you make sure that a model conforms to specified constraints. |
Get UML model elements from IDataObject | IElement, IShape | When an element is dragged from UML Model Explorer or a UML diagram to another diagram or application, it is serialized as an IDataObject. |
Edit UML sequence diagrams by using the UML API | IInteraction, ILifeline, IMessage | Creating and updating an interaction diagram is slightly different from working with the other diagram types. |
Extend layer diagrams | ILayer, ILayerDiagram | You can write code to create and edit layer diagrams, and also validate program code against them. |
About the Implementation
The UML modeling tools are built on Domain-Specific Language Tools. Each package and each diagram is represented by a Domain-Specific Language Tools model, and a collection of rules and other methods maintains consistency between them.
Types from that platform are visible in some of the assemblies that you reference in order to write UML extensions. Although you can make extensions to the UML tools by accessing the Domain-Specific Language Tools API, you should bear the following considerations in mind:
You might find that some apparently simple changes introduce inconsistencies and unexpected effects.
The implementation may change in the future, so that adaptations you make using the Domain-Specific Language Tools API might no longer work.
The API assemblies
This table summarizes the assemblies that provide extensibility for the UML tools, and the namespaces that you are recommended to use.
Assembly | Namespaces | Provides access to: |
---|---|---|
Microsoft.VisualStudio.Uml.Interfaces | (All) | The UML types. |
Microsoft.VisualStudio.ArchitectureTools.Extensibility | Microsoft.VisualStudio.ArchitectureTools.Extensibility.Uml | Creation methods |
Microsoft.VisualStudio.ArchitectureTools.Extensibility.Presentation | Diagrams and Shapes | |
Microsoft.VisualStudio.ArchitectureTools.Extensibility | The modeling project | |
Microsoft.VisualStudio.Modeling.Sdk.[version] | Microsoft.VisualStudio.Modeling.ExtensionEnablement | Menu command extension. Linked Undo transactions. |
Microsoft.VisualStudio.Modeling.Validation | Validation | |
(other namespaces) | Recommended only for advanced use. | |
Microsoft.VisualStudio.Modeling.Sdk.Diagrams.[version] | Microsoft.VisualStudio.Modeling.Diagrams.ExtensionEnablement | Gesture handlers. |
(other namespaces) | Recommended only for advanced use. | |
Microsoft.VisualStudio.TeamFoundation.WorkItemTracking | Microsoft.VisualStudio.TeamFoundation.WorkItemTracking | Links to work items. |
Microsoft.TeamFoundation.WorkItemTracking.Client | Microsoft.TeamFoundation.WorkItemTracking.Client | Work items and their fields. |
Microsoft.TeamFoundation.Client | Microsoft.TeamFoundation.Client | Work items and their fields. |
System.ComponentModel.Composition | System.ComponentModel.Composition | Export and Import for MEF components |
System.Linq | System.Linq | Easy manipulation of collections, especially when dealing with relationships. |
See Also
Extend UML models and diagrams API Reference for UML Modeling Extensibility