Programming with the UML API

The UML API of Visual Studio Ultimate lets you write code to create, read, and update UML models and diagrams.

In addition to the API reference pages, the following topics describe the API.

Topic

Example types and methods described

Features described

How to: 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 Ultimate, 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".

How to: Create Elements and Relationships

IPackage.CreateClass()

IClass.CreateOperation()

Each element type has methods for creating its children.

How to: Display a 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.

How to: Navigate the UML Model

IModelStore

IDiagramContext

The Model Store stores the model.

The Diagram Context gives you access to the current diagram and store.

How to: Link Model Updates using Transactions

ILinkedUndoContext

You can link a series of changes into one transaction.

How to: 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.

How to: Define Validation Constraints for UML Models

ValidationContext

You can define validation rules that help you make sure that a model conforms to specified constraints.

How to: 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.

How to: Edit 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.

Extending 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.12.0

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.12.0

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

Concepts

Extending UML Models and Diagrams

Other Resources

API Reference for UML Modeling Extensibility