[英]Insert a snippet from a Visual Studio macro
我遇到一种情况,我想运行一个Visual Studio宏,该宏的用户在InputBox中输入某些内容,然后插入一个代码段并将该文本包含在其中。 不幸的是,我不知道如何从宏代码中插入代码段。 好像是
DTE.ExecuteCommand("Edit.InvokeSnippetFromShortcut")
要么
DTE.ExecuteCommand("Edit.InvokeSnippetFromShortcut", "theSnippetName")
但是那些不起作用。 有任何想法吗?
您可以使用以下代码插入代码段。
DTE.ActiveDocument.Selection.Text = "snippetshortcut"
DTE.ExecuteCommand("Edit.InsertTab")
如果使用的是VS 2010,则需要两次调用DTE.ExecuteCommand(“ Edit.InsertTab”)。
您需要确定应在何处选择此代码。 要在当前文本选择中插入文本,您需要使用以下代码:
Dim textSelection As EnvDTE.TextSelection
textSelection = DTE.ActiveWindow.Selection
textSelection.Insert(MyTextVarHere)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.