String.Format

Resharper is convenient for turning "+"-concatenated strings into String.Format

However, I think that you shold have a refactoring for string.Format.

"Hi, This is Thomas".

By marking the word Thomas I wish to have a refactoring to:

String.Format("Hi, This is {0}","Thomas");

By marking "Hi", I wish to have refactoring into

String.Format("{1}, This is {0}","Thomas","Hi");

I would then have the options of marking the "Thomas" or "Hi" and turn them into variables.

Basically, I think that String.Format should have extract and expand inline (at least for literal strings). And that the Alt-Enter should respond to current selection, not just cursor position.

1 comment
Comment actions Permalink

Another example:

private static string GetPSFilePath(this ProcessStation ps)
        {
            var psNo = ps.Address;
            var psToolOutputDirectory = GetToolOutputDirectory();
            return string.Format("{0}\\{1:D3}\\{2}{1}.ps",psToolOutputDirectory,psNo,GetProjectName());
        }

This method returns a full path.

I want to create a method that returns exactly the same path, but with ".io" extension instead of ".ps"

How do I, elegantly and with safe tool support, refactor into

private static string GetPSFilePath(this ProcessStation ps)
        {
            var psNo = ps.Address;
            var psToolOutputDirectory = GetToolOutputDirectory();
            return string.Format("{0}.ps",GetFileBasePath(psNo,psToolOutputDirectory));
        }

0

Please sign in to leave a comment.