Resharper string.format shortcut

前端 未结 5 1206
礼貌的吻别
礼貌的吻别 2021-01-13 04:04

I often find myself writing

var message = \"Hello {0}\";

and then going back and typing in

var message = string.Format(\"He         


        
5条回答
  •  轮回少年
    2021-01-13 04:47

    You can almost do this with a Visual Studio snippet (i.e. without ReSharper).

    Save the following as a file with a .snippet extension.

    
    
        
    string format Matthew Strawbridge Wraps the selected text with string.Format SurroundsWith
    variable value

    Then you can load it via Tools | Code Snippets Manager | Import.

    Once the snippet is available, you can type

    var message = "Hello {0}"
    

    but you'd have to select the string and then press CtrlK CtrlS and select the snippet name to apply it. This would generate

    var message = string.Format("Hello {0}", value);
    

    with the value part selected for editing.

    Edit: There's also a Snippet Designer extension that makes working with snippets easier.

提交回复
热议问题