开发者

Make visual studio autoformat my source code?

I've searched but does Visual Studio 2008 have a setting for C# where it will autoformat/beautify my code as I write it? There is a setting for VB.NET called "prettify". I've also searched the archives already and found a macro to execute this on save and I know I can drag and drop it onto the toolbar but I开发者_运维问答 want it to work without my doing ANYTHING for both ASPX and CS files.

Is this possible via built-in setting, modification, or available from an add on? Thanks


Select the code block and press Ctrl+K+F


Would a keyboard shortcut work for you?

Ctrl + k + d - format the whole document.

Ctrl + k + f - format selection.

In C#, you can also delete and reinsert the } for a similar effect on the block in question.


Under Tools | Options, you can navigate to Text Editor | C# | Formatting and select all three checkboxes. This will cause your code to be auto formatted per the formatting options in C# | Formatting on those certain events: namely typing a semi-colon, typing a close stache, or pasting in code.

Note: In order for this to work, the code in the file must be able to compile without errors. Also, if you don't have any formatting options specified, or left at their default values, you may not see any difference.


You could also look into tools like ReSharper (disclaimer: I work for them)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜