visual-studio - 如何从 Visual Studio 2012 中的 CommandBarButton 获取 EnvDTE.Command

标签 visual-studio visual-studio-2012 visual-studio-extensions

我正在尝试通过菜单查找所有已启用的 resharper 命令。我可以使用以下代码找到所有菜单项。但是我找不到如何从 DTE 命令集合中获取实际命令。

var resharper = ((CommandBars)_dte.Application.CommandBars)["RESHARPER"];
var refactor = (CommandBarPopup)resharper.Controls["&Refactor"].Control;
foreach (var c in refactor.Controls)
{
    var cbb = c as CommandBarButtonClass;
    if (cbb != null)
    {
        yield return new VoiceCommand
        {
            Command = _dte.Commands.Item(???),
            Key = cbb.accName,
        };  
    }
}

我应该使用什么属性来查找命令(??? 上面)?

谢谢, 埃里克

最佳答案

您想使用 CommandInfo method ,像这样:

Guid guid;
int id;
_dte.Commands.CommandInfo(cbb, out guid, out id);
yield return new VoiceCommand
{
    Command = _dte.Commands.Item(guid, id),
    Key = cbb.accName,
};  

关于visual-studio - 如何从 Visual Studio 2012 中的 CommandBarButton 获取 EnvDTE.Command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17003364/

相关文章:

asp.net-mvc-4 - 添加 Controller 时出现 nunit Framework not found 错误

visual-studio - 向 Visual Studio 添加 Objective C 语法突出显示

visual-studio-2013 - Visual Studio 2013 - JSLint.NET 已安装但未显示在工具中?

c# - 如何引用添加到 Visual Studio 项目的 json 文件

c++ - 链接 : fatal error LNK1561: entry point must be defined ERROR IN VC++

c++ - 在动态加载的 dll 中查找名称错误的函数

visual-studio-2012 - TF10175 : The team project does not exists

javascript - 在浏览器中运行 TypeScript 项目

mysql - 尝试并捕获插入 MySQL 中的 MysqlCmd.ExecuteNonQuery

c# - Roslyn 向现有类添加新方法