命令将符号写为文本(Resharper?VS2010?)

时间:2010-06-27 20:32:18

标签: keyboard-shortcuts resharper

我正在观看使用Resharper(在VS 2010或2008上,不确定)的人的截屏视频,他们可以用字符串文字填写测试名称:

public class FooTest
{
    public void "runs backgrounnd process until complete"

然后一些命令将其转换为

public class FooTest
{
    public void runs_backgrounnd_process_until_complete()
    {

我想知道是否有人知道那个命令是什么。

2 个答案:

答案 0 :(得分:0)

看起来像一个“实时模板”。如果您注意到,他键入fact,然后由测试方法的骨架替换。编辑,看起来像来自xUnit.net contrib项目。你也应该可以为nUnit测试用例做类似的事情。

答案 1 :(得分:0)

这是一个视觉工作室宏,最初来自JP Boodhoo的Nothing But .NET Boot Camp课程。就是这样:

 Sub ConvertLine()
        If DTE.ActiveDocument Is Nothing Then Return

        Dim isOpen As Boolean = OpenUndo("ConvertLine")

        Dim selection As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
        selection.SelectLine()
        If selection.Text = "" Then Return

        Dim classKeyword As String = "class """
        Dim methodKeyword As String = "void """
        Dim classIndex As Integer = selection.Text.IndexOf(classKeyword)
        Dim methodIndex As Integer = selection.Text.IndexOf(methodKeyword)
        If classIndex + methodIndex < 0 Then Return

        Dim index = CType(IIf(classIndex >= 0, classIndex, methodIndex), Integer)
        Dim prefix = selection.Text.Substring(0, index) + CType(IIf(classIndex >= 0, classKeyword, methodKeyword), String)
        Dim description As String = selection.Text.Replace(prefix, String.Empty)

        Dim conversion As String = Common.ReplaceSpacesWithUnderscores(description)
        conversion = Common.ReplaceApostrophesWithUnderscores(conversion)
        conversion = Common.ReplaceQuotesWithUnderscores(conversion)

        selection.Text = prefix.Replace("""", String.Empty) + conversion
        If prefix.Contains(methodKeyword) Then selection.LineDown() Else selection.LineUp()
        selection.EndOfLine()

        CloseUndo(isOpen)
    End Sub