ReSharper 2016.1 Help

Extract Class from Parameters

ReSharper | Refactor | Extract | Extract Class from Parameters…

This refactoring allows you to quickly create a new class or structure using parameters of a method. The selected parameters are converted into fields with properties, The method itself and all its usages are converted so that the method takes the newly created class as a parameter.

Consider the following example:

Before refactoringAfter refactoring
class TestClass { public void DrawCircle(Point center, float radius) { // draw... . } }
class Circle { private Point center; private float radius; public Circle(Point center, float radius) { = center; this.radius = radius; } public Point Center { get { return center; } } public float Radius { get { return radius; } } } class TestClass { public void DrawCircle(Circle circle) { // draw... . } }

To extract a class from parameters of a function

  1. Place the caret at the declaration or a usage of a method in the editor, or select it in the File Structure Window.
  2. Do one of the following:
    • Press Ctrl+Shift+R and then choose Extract Class from Parameters
    • Right-click and choose Refactor | Extract Class from Parameters on the context menu.
    • Choose ReSharper | Refactor | Extract | Extract Class from Parameters… in the main menu.
    The Extract Class from Parameters dialog will open.
  3. Choose whether you want to create a class or a structure and whether it should be nested in the current type or in the top level in the current namespace.
  4. Specify a name for the new class.
  5. Choose which parameters should become members of the new class.
  6. To apply the refactoring, click Next.
  7. If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
ReSharper. Creating a class from method's parameters

This feature is supported in the following languages/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts Protobuf JSON
feature_available feature_available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

See Also

Last modified: 19 August 2016