What are the Resharper 4 shortcuts to
Create a class from usage? e.g. I type "var p = new Person();", and I want to now create the person class.
Move this class to its own file? When the Person class exists in the same file next to my Order class, what is the shortcut to move it.
I can't seem to find these shortcuts on the cheatsheet or the Internet.
Choose Tools | Options from the menu and then go to Environment | Keyboard page. Use the shortcut tables to find the alias of the command, to which you are going to assign a new shortcut. If some command does not have a default shortcut, you can find its alias under the title of the corresponding help page.
Press Ctrl+Shift+R and then choose Rename. Right-click and choose Refactor | Rename from the context menu. Choose ReSharper | Refactor | Rename… from the main menu.
Press Ctrl+Shift+R and then choose Extract Class. Right-click and choose Refactor | Extract Class from the context menu.
Type the line out:
var p = new Person();
Person
will be highlighted in red as an error by ReSharper. Put the caret on it and press ALT+ENTER to invoke the quick-fix context menu. Select Create class 'Person'.
The cursor will then be on the new class' name, so press ALT+ENTER again to invoke the context-sensitive quick-fix menu again and select Move to another file to match type name.
That's just two actions - really quick and easy. After a while, it (like most R# commands) becomes muscle memory. Like driving, walking or chewing gum.
FOR BONUS POINTS
The above is all you need to do what you wanted, but you can take it a step or two further:
If you'd rather the class was moved to a different namespace, you can press SHIFT+CTRL+R and select Modify Namespace....
If you'd rather the class was moved to a different project entirely, you can press SHIFT+CTRL+R and select Move to Folder....
The great thing is - ReSharper will make all necessary changes to namespaces to make sure things still compile. With one gotcha - only if the project you move the classes to is referenced by the one you move them from. You have two choices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With