Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a method parameter object with ReSharper in a few seconds?

Is it possible to select all the parameters of a method and ask ReSharper to create a class from those parameters as a "method parameter object?"

like image 589
pencilCake Avatar asked Nov 01 '10 10:11

pencilCake


1 Answers

ReSharper supports the command Extract Class From Parameters:

The Extract Class From Parameters refactoring allows you to quickly create a new class or structure using (some of) the parameters of a given method. ReSharper analyses the selected method and detects the variables that can be converted into members. After extraction, the new class is created with the necessary fields generated from the selected method's parameters.

To invoke it:

  1. Place the cursor on the method with the parameters you want to generate a class for
  2. Press Ctrl + Shift + R
  3. Select 'Extract Class From Parameters'
  4. Do any additional configuration in the dialog box.
like image 131
Ray Avatar answered Sep 22 '22 21:09

Ray