开发者

Refactor nested class - move to separate file - visual studio 2008

I am looking for a way to extract a nested inner class so that it is in a separate file. Is there an easy way to do this in Visual Studio 2008 (eg, using the refactor menu)?

开发者_JAVA百科

EDIT

Maybe a refactoring menu option isn't necessary if manual refactoring is simple enough.


if i understand correctly, you can use partial classes http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx


I don't remember there being a built in refactoring for that, but it is available in Resharper.

If you don't have Resharper and have a lot of them you need to refactor, you could always download and use the trial.


DevExpress offers a free coding assistance tool called CodeRush Express which offers this refactoring. Here's a link to the page showing the refactoring.

I own a license to their full-blown CodeRush w/ Refactor Pro, and I love it.

EDIT

Following the edit of the question, I just wanted to add that I'm able to do that refactoring using the following keystrokes (with the cursor on the name of the nested class)

  1. Ctrl+` (opens refactor menu)
  2. Enter (or arrowing down to the option if it's not already selected)

That automatically creates a new file in the project with the name of the nested class as the name of the file, moves the nested class to that file, removes it from the original location, and drops a marker at the place where the nested class was removed. Hitting Esc takes you back to where the extracted class was removed.

It is a huge time-saver. Granted, my day's not full of extracting nested classes, but it's an example of how saving a couple of minutes here and there can really help remove the friction from some common development tasks.


This question is a bit outdated, but I found a very good solution since Visual Studio 2017:

If you have a nested class, place your cursor on the class name. A little screwdriver appears on the left side (alternative press CTRL + .).

In the context menu you can select "move to myClass.cs".

Now it will refactor your nested class in a seperate file with all namespace changes.

Here is how it looks:

Refactor nested class - move to separate file - visual studio 2008

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜