0

我有一种情况,我希望将变量大写以用于文档,例如
(例如,trivalized)

///AT+$COMMAND$

void At$COMMAND$()
{
}

所以我希望模板的用户输入类似“Blah”的内容,并在方法名称中使用,但文档部分更改为“BLAH”。

例如

///AT+BLAH
void AtBlah()
{
}

我可以这样做吗?我在宏中看到我可以将第一个字母大写,但我希望整个单词大写。是否可以创建自定义宏?

4

1 回答 1

0

他们刚刚更新了文档以满足 Resharper 8 中宏的更改。您可以在http://confluence.jetbrains.com/display/NETCOM/4.04+Live+Template+Macros+%28R8%29查看

使用新文档很容易,我的实现在这里:

using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using JetBrains.DocumentModel;
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Macros;
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Hotspots;

namespace ReSharperPlugin
{
    [MacroDefinition("LiveTemplatesMacro.CapitalizeVariable", // macro name should be unique among all other macros, it's recommended to prefix it with your plugin name to achieve that
    ShortDescription = "Capitalizes variable {0:list}", // description of the macro to be shown in the list of macros
    LongDescription = "Capitalize full name of variable" // long description of the macro to be shown in the area below the list
    )]
    public class CapitalizeVariableMacro : IMacroDefinition
    {
        public string GetPlaceholder(IDocument document, IEnumerable<IMacroParameterValue> parameters)
        {
            return "A";
        }

        public ParameterInfo[] Parameters
        {
            get { return new[] {new ParameterInfo(ParameterType.VariableReference)}; }
        }
    }

    [MacroImplementation(Definition = typeof(CapitalizeVariableMacro))]
    public class CapitalizeVariableMacroImpl : SimpleMacroImplementation
    {
        private readonly IMacroParameterValueNew _parameter;

        public CapitalizeVariableMacroImpl([Optional] MacroParameterValueCollection parameters)
        {
            _parameter = parameters.OptionalFirstOrDefault();
        }

        public override string EvaluateQuickResult(IHotspotContext context)
        {
            return _parameter == null ? null : _parameter.GetValue().ToUpperInvariant();
        }
    }
}
于 2014-01-15T16:20:54.560 回答