Anonymous Type to Real Class Refactoring

后端 未结 1 687
终归单人心
终归单人心 2021-01-02 08:33

Is there an easy way to refactor an anonymous type into a class? I frequently prototype my code with anonymous types, then have to go back and re implement the various class

相关标签:
1条回答
  • 2021-01-02 08:58

    Using ReSharper 5.1 (I would expect this has been available since version 4, the first with C# 3.0 support), with the cursor anywhere from just before the new to just after the closing } in this code:

            var v = new {Name = "Brian"};
    

    bring up the Refactor This... menu (typically with Ctrl+Shift+R), and one of the options is Replace Anonymous Type With Named Class..., which brings up this dialog:

    ReSharper's Replace Anonymous Type With Named Class dialog

    0 讨论(0)
提交回复
热议问题