Resharper - 用于替换选择的Visual Studio 2012自定义快捷方式

时间:2014-07-18 22:20:16

标签: visual-studio-2012 resharper resharper-8.0

在我一直在研究的网络项目中,我们有像

一样的字符串文字
<div class="title">This is Title</div>
<div class="text">This is some text<div>

为了使应用程序具有多语言功能,我需要将所有这些文字替换为一些辅助方法:

<div class="title">@TranslationHelper.Translate("This is Title")</div>
<div class="text">@TranslationHelper.Translate("This is some text")<div>

我想通过Resharper 8.0或Visual Studio 2012创建自定义快捷方式(例如CTRL + ALT + M)。

当我选择要转换的文本并按下我定义的快捷方式时,Visual Studio应该用我定义的格式替换选择。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

您可以使用Resharpers Surround With功能来实现此功能。首先打开模板资源管理器

  

Resharper - &gt;模板资源管理器

然后点击新模板:

enter image description here

在模板编辑器中输入所需的字符串并保存(Ctrl-S)

enter image description here

现在将光标放在所需的文本中。另请注意,您可以使用Resharpers Extend Selection功能快速选择文本(快捷方式为Ctrl-Alt-RightArrow)

选择文本后,选择按Ctrl-E,U(Resharper Surround with)

enter image description here

点击“更多”,您可以在其中选择新模板并确保将其添加到快速列表中,以便将其添加到列表中以供下次使用

enter image description here

enter image description here

相关问题