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.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.10.0.dll)

Syntax

'Declaration
Public Interface ICommandExtension
public interface ICommandExtension
public interface class ICommandExtension
type ICommandExtension =  interface end
public interface ICommandExtension

The ICommandExtension type exposes the following members.

Properties

  Name Description
Public property Text The visible label that identifies this command in the menu.

Top

Methods

  Name Description
Public method Execute Invoked when the user clicks this command on the menu.
Public method QueryStatus 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.

Top

Remarks

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:

[Export(typeof(ICommandExtension))]

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

[ClassDesignerExtension]

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 How to: Define a Menu Command on a Modeling Diagram.

See Also

Reference

Microsoft.VisualStudio.Modeling.ExtensionEnablement Namespace