Command Interface

Represents a command in the environment.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

public interface Command

The Command type exposes the following members.

Public propertyBindingsSets or gets the list of keystrokes used to invoke the command.
Public propertyCollectionGets the Commands collection containing the Command object.
Public propertyDTEGets the top-level extensibility object.
Public propertyGuidGets the GUID for the given object.
Public propertyIDGets the ID within a command group GUID used to represent the command.
Public propertyIsAvailableGets a value indicating whether or not the Command is currently enabled.
Public propertyLocalizedNameGets the localized name of the command.
Public propertyNameGets the name of the object.

Public methodAddControlCreates a persistent command bar control for the command.
Public methodDeleteRemoves a named command that was created with the AddNamedCommand method.

Reference this object by using Item.

You can reference this object a number of ways, such as by using the canonical name or the GUID ID. The easiest way to invoke most commands is by using ExecuteCommand. You can use Raise for the rare instances when you must invoke a command without a name.

' Macro code.
Sub CommandExample()
  ' Creates a text document listing all command names.
  Dim Cmd As Command
  Dim Doc As Document
  Dim TxtDoc As TextDocument

  ' Create a new text document.
  DTE.ItemOperations.NewFile ("General\Text File")
  Set Doc = ActiveDocument
  Set TxtDoc = Doc.Object("TextDocument")
  For Each Cmd In Commands
  If (Cmd.Name <> "") Then
    TxtDoc.Selection.Text = Cmd.Name & vbLF
  End If
End Sub

Community Additions