开发者

Visual Studio 2010 macro package or extension to reformat code?

Today I have been finding myself doing a lot of rearranging of code. Like converting this:

var assetPlacement = new AssetPlacement
    {
        Transform = worldSpaceTransform,
    };

to this:

var assetPlacement = new AssetPlacement { Transform = worldSpaceTransform, };

Or the reverse, when more params are added. And many more rearranging of deck chairs on the Titanic kind of thing to make OCD types like me happy.

Are there any good extensions or macros out there that provide specific types of code reformatting/refactoring like the above?

Update:

I am not looking for a "format my document/selection according to pretty-开发者_开发百科printing rules" and Ctrl-K whatever. Let's imagine I know my way around Visual Studio pretty well. ReSharper also does not do what I'm after.

I am looking for specific stylistic refactorings. Like changing this:

public string Foo { get { return _foo; } set { _foo = value; } }

to this:

public string Foo
{
    get { return _foo; }
    set { _foo = value; }
}

...on a command. Or doing the reverse - going from the second form to the first form, on a different command. Without editing profiles and checking boxes. Easily available to go either way on a hotkey or context menu.

Visual Studio does come with a sample macro, for example, that reformats a block of text to align all the equals signs.

That's the kind of thing I'm after. Targeted stylistic reformatting.


Visual Studio can do some automatic formatting for you from the Edit menu under Advanced, but for more complicated code formatting I suggest ReSharper. A good list of what you can do is described here.


ctrl K, ctrl + D does this for you (Edit / Advanced / Format Document) . It's built in Visual Studio. You can adapt the rules in Options / Text Editor / C # / Formatting.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜