【问题标题】:How to add a .cw Postfix Template in Visual Studio\Resharper like .sout template in IntelliJ?如何在 Visual Studio\Resharper 中添加 .cw 后缀模板,如 IntelliJ 中的 .sout 模板?
【发布时间】:2023-03-08 12:40:01
【问题描述】:

我正在从 Java 过渡到 C#。 在 IntelliJ 中有一个后缀模板,如:

String expr = "John";
//writing expr.sout gives:
System.out.println(expr);

有没有办法创建像 expr.cw 这样返回 Console.WriteLine(expr); 的模板?在 Visual Studio\Resharper 中?

【问题讨论】:

  • 您确实应该添加您尝试过的内容以及错误所在。这将使我们更好地了解您遇到的问题。

标签: c# visual-studio autocomplete resharper


【解决方案1】:

使用JetBrains.Annotations 并创建SourceTemplate 是一种可能的解决方案。 比如在项目中添加如下静态类:

using System;
using JetBrains.Annotations;

namespace SpeechRecognition
{
    public static class ResharperHelper
    {
        [SourceTemplate]
        public static void cw(this string str)
        {
            Console.WriteLine(str);
            //$ $END$
        }
    }
}

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多