Class BaseCommand<T>
A base class that makes it easier to handle commands.
Inheritance
Inherited Members
Namespace: Community.VisualStudio.Toolkit
Assembly: Community.VisualStudio.Toolkit.dll
Syntax
public abstract class BaseCommand<T>
where T : class, new()
Type Parameters
Name | Description |
---|---|
T | The implementation type itself. |
Examples
[Command("489ba882-f600-4c8b-89db-eb366a4ee3b3", 0x0100)]
public class TestCommand : BaseCommand<TestCommand>
{
protected override Task ExecuteAsync(OleMenuCmdEventArgs e)
{
return base.ExecuteAsync(e);
}
}
Properties
| Improve this Doc View SourceCommand
The command object associated with the command ID (guid/id).
Declaration
public OleMenuCommand Command { get; }
Property Value
Type | Description |
---|---|
Microsoft.VisualStudio.Shell.OleMenuCommand |
Package
The package class that initialized this class.
Declaration
public AsyncPackage Package { get; }
Property Value
Type | Description |
---|---|
Microsoft.VisualStudio.Shell.AsyncPackage |
Methods
| Improve this Doc View SourceBeforeQueryStatus(EventArgs)
Override this method to control the commands visibility and other properties.
Declaration
protected virtual void BeforeQueryStatus(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e |
Execute(Object, EventArgs)
Executes synchronously when the command is invoked.
Declaration
protected virtual void Execute(object sender, EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | |
System.EventArgs | e |
Remarks
Use this method instead of ExecuteAsync(OleMenuCmdEventArgs) if you're not performing any async tasks using async/await patterns.
ExecuteAsync(OleMenuCmdEventArgs)
Executes asynchronously when the command is invoked and Execute(object, EventArgs)
isn't overridden.
Declaration
protected virtual Task ExecuteAsync(OleMenuCmdEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs | e |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
Use this method instead of Execute(Object, EventArgs) if you're invoking any async tasks by using async/await patterns.
InitializeAsync(AsyncPackage)
Initializes the command. This method must be called from the Microsoft.VisualStudio.Shell.AsyncPackage.InitializeAsync(System.Threading.CancellationToken, System.IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData>) method for the command to work.
Declaration
public static Task<T> InitializeAsync(AsyncPackage package)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.VisualStudio.Shell.AsyncPackage | package |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> |
InitializeCompletedAsync()
Allows the implementor to manipulate the command before its execution.
Declaration
protected virtual Task InitializeCompletedAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
This method is invoked right after the InitializeAsync(AsyncPackage) method is executed and allows you to manipulate the Command property etc. as part of the initialization phase.