问题描述
我希望能够突出显示一段文字并删除任何;"在突出显示的部分中.
I would like to be able to highlight a section of text and remove any ';' in the highlighted section.
我已经写了一个有段环绕"来封装突出显示的文本,但也想务实地修改文本和我不确定如何.
I've written a "surround with snippet" to encapsulate the highlighted text, but would also like to pragmatically modify that text and am unsure how.
我使用Visual Studio中的代码段设计器"扩展程序来创建代码段.
I use the "Snippet Designer" extension in visual studios for snippet creation.
我希望突出显示的文本" RunMethod1(var1); "
将被转换为".Then(() => RunMethod1(var1) ) "
,即不使用分号.
I would expect the highlighted text " RunMethod1(var1); "
to be converted to".Then(() => RunMethod1(var1) ) "
ie without the semi-colon.
推荐答案
您可以将以下命令用于 Visual指挥官删除所有;"在选择中,并用"Then"(语言:C#)括起来:
You can use the following command for Visual Commander to remove any ';' in the selection and surround it with 'Then' (Language: C#):
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
ts.Text = ".Then(() =>" + ts.Text.Replace(";", "") + ") ";
}
}
这篇关于在Visual Studio中,有什么方法可以在编辑器中以编程方式修改选定的编辑器文本?代码段?宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!