views:

179

answers:

1

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?

A: 

Check out these two pages for macro help. I don't think his macro is converting spaces to underscores, but it sounded similar.

http://github.com/ArildF/RogueSharper

http://chrislaco.com/articles/writing-resharper-45x-macros/

I hope this helps.

Eric Krause
Thanks for your answer. My problem isn't really writing a macro, but more having it run on a variable, after I tab out of that variable.
Luhmann