Resharper Live Template Macro that changes variable name upon exit

Posted by Luhmann on Stack Overflow See other posts from Stack Overflow or by Luhmann
Published on 2010-02-23T21:36:54Z Indexed on 2010/03/17 14:01 UTC
Read the original article Hit count: 614

I would like to create a Resharper Live Template that changes all spaces to underscores ind my "fact" Live template variable $testname$:

<Fact()> _
Public Sub $testnames$()
    ' Arrange
    $END$

    ' Act

    ' Assert

End Sub

I have this:

    [Macro("applyRegex", ShortDescription = "Run on {#0:variable}", LongDescription = "")]
    class ApplyRegexMacro : IMacro
    {
        public string EvaluateQuickResult(IHotspotContext context, IList<string> arguments)
        {
            return Regex.Replace(arguments[0], " ", "_", RegexOptions.IgnoreCase);
        }

        public HotspotItems GetLookupItems(IHotspotContext context, IList<string> arguments)
        {
            return null;
        }

        public string GetPlaceholder()
        {
            return "placeholder";
        }

        public bool HandleExpansion(IHotspotContext context, IList<string> arguments)
        {
            return false;
        }

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

But this only runs when i press tab. I want the macro to run after I tab out of $testname$.

I want to be able to just write the test name in a single line of text with spaces, and then the Macro turns all the spaces into underscores.

Is this possible?

© Stack Overflow or respective owner

Related posts about resharper

Related posts about live-templates