Anonymous type for real-class refactoring

Is there an easy way to reorganize an anonymous type into a class? I often prototype my code with anonymous types, then I have to go back and reimplement the various classes, since they need to be used outside their local scale. I am using resharper and wondering if there is an easy way to do this.

+8
c # anonymous-types resharper
source share
1 answer

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

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

display the menu Refactor This... (usually with Ctrl + Shift + R ), and one of the parameters is Replace Anonymous Type With Named Class... , which calls this dialog box:

ReSharper's Replace Anonymous Type With Named Class dialog

+12
source share

All Articles