ICommandExtension Interface


Implement and export this interface from a MEF extension to provide a menu command for modeling diagrams.

Namespace:   Microsoft.VisualStudio.Modeling.ExtensionEnablement
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)

public interface ICommandExtension


The visible label that identifies this command in the menu.


Invoked when the user clicks this command on the menu.


Implement this to define whether your command should be visible and enabled. Set command.Visible and command.Enabled. Do not change the state of the model.

To define a menu command for a UML diagram, you can implement this interface in a Visual Studio Extension. In the extension.manifest, your assembly must be identified as a MEF component. You must prefix your class with an Export attribute:


You should also provide an attribute for each diagram type on which you want the command to appear:


Define the command as a public class:

public class NameSwapper : ICommandExtension {

Inside your class, you should import IDiagramContext, to enable you to access the current diagram, selected shapes, model elements, and model store:

[Import] public IDiagramContext Context { get; set; }

You can also import IServiceProvider, in order to obtain access to Visual Studio components such as Solution Explorer:

[Import] public IServicerProvider ServiceProvider { get; set; }

If your command will make several changes to the model, you might want to group them together into a single transaction, so that you can abandon the whole group if one fails, and so that the user can undo the whole group with a single undo command. ILinkedUndoContext allows you to create a transaction:

[Import] public ILinkedUndoContext LinkedUndoContext {get; set;}

For more information, see Define a menu command on a modeling diagram.

Return to top