Question

I am trying to create a surround-with template with resharper that formats a selection like this

string foo = "A text with spaces";

into this:

string foo = Translate("ATextWithSpaces");

I want to select the "A text with spaces" myself, press the surround-with shortcut and just watch it happen!

I have a template that produces

string foo = Translate("A text with spaces")

...but that's not good enough for me. Any suggestions?

Was it helpful?

Solution

Expanding on my comment:

You could create a new method that formats your string as you want it, something like:

public string RemoveSpaces(string input)
{
    return new System.Globalization.CultureInfo("en-GB", false).TextInfo.ToTitleCase(input).Replace(" ", "");
}

OTHER TIPS

If you're prepared to venture into ReSharper plug-in dev territory, this yields a very, very simple plug-in that would take minutes to implement. Basically, what you can do is make a context action that, when the caret is on a string literal, would take said literal, remove spaces (with string.Replace), then create a new expression using e.g., CSharpElementFactory.CreateExpressionAsIs("Translate($1)", x) where x is the modified literal.

If you're interested in doing this and need more info, feel free to contact me (skype: dmitri.nesteruk, email: dn at jetbrains dot com) with any questions you may have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top