简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM