To convert an anonymous type to a named type
  1. Locate an anonymous type and position the caret at either its object initializer or new keyword:
    Convert_Anonymous_to_Named_Type__before
  2. Select ReSharper | Refactor | Convert | Anonymous to Named Type. The Replace Anonymous Type with Named Class dialog box will appear:
    Convert_Anonymous_to_Named_Type__dialog_box
  3. Specify a name for the new class, and configure the following options:
    • Scope: ReSharper can convert anonymous types with compatible object initializers in the scope of either the current method or the whole solution.
    • Location: the new named type can be nested in the current type, or created as an independent entity.
    • How to generate properties: ReSharper can generate either read and write auto-properties, or read-only properties with backing fields in the new class.
    • How to generate methods: an an option, you can choose to create stubs for Equals(), GetHashCode(), and ToString() method overrides in the new class.
    • Show processed usages in 'Find Results': if this check box is selected, ReSharper will show the new named type as well as all its usages in the Find Results window (see screenshot below).
  4. Click Next. The anonymous type will be converted to a new named class:
    Convert_Anonymous_to_Named_Type__after__declaration
    All usages of the type found within the specified scope will be modified accordingly:
    Convert_Anonymous_to_Named_Type__after__usage
    If you have selected Show processed usages in 'Find Results', the new class and any modified type usages will be shown in the Find Results tool window:
    Convert_Anonymous_to_Named_Type__Find_Results