【问题标题】:Custom shorthand Visual Studio 2017自定义速记 Visual Studio 2017
【发布时间】:2017-08-28 22:47:24
【问题描述】:

有没有办法在 Visual Studio 2017 中创建自定义速记。 就像 ctor 或 prop 一样?

我想为单元测试创​​建一个简写,只需输入例如 test 然后有一个预定义的函数来编辑,例如:

public void Method_Condition_Expected()
{
   // Arrange

   // Act

   // Assert
}

【问题讨论】:

标签: visual-studio shorthand


【解决方案1】:

正如@Peter B 对 Visual Studio 本身的建议,您可以使用 Snippet Designer(工具->代码片段管理器)来完成。

我现在发现,我安装的工具 ReSharper (2016.3) 可以选择创建所谓的 Live-Template。

这样,我可以创建一个这样的模板:

public void $Method$_$Condition$_$Expected$()
{
    // Arrange

    // Act

    // Assert
}

现在最好的部分是,我可以在 Method、Condition 和 Expected 中使用选项卡并覆盖这些值。

如何使用:在 Visual Studio 中标记一个代码区域,例如上面的代码,然后点击 Resharper->Tools->Create Live Template from Selection->Create and Edit

现在用 $ 包装代码区域以进行制表符,例如 $Method$ 并给出一个快捷方式名称,例如 test。

我希望这对其他人也有帮助。

有关 Visual Studio Snippet Manager 和 Resharper 实时模板之间的更详细比较,请参阅 Difference between Live Template and Visual Studio Snippet

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 2023-04-03
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2018-05-15
    • 2018-11-13
    • 2018-04-12
    • 1970-01-01
    相关资源
    最近更新 更多