Disable Visual Studio Reformat #if ... #endif

Assuming I have the following code in C #:

void Func () { int i=3; #if DEBUG ... #endif for (int j=0;j<i;j++) { ... } } 

If I use Edit->Advanced->Format document , it is reformatted to this (using my current code formatting settings):

 void Func () { int i = 3; #if DEBUG ... #endif for ( int j = 0; j < i; j++ ) { ... } } 

Is there a way to prevent #if and #endif lines from moving to the far left? I could not find any settings for them, but I hope that there will be a registry setting that will control how it works.

I welcome you any advice: this behavior is driving me crazy, since my code contains several hundreds of such blocks, they continue to be violated by VS.

+8
c # visual-studio-2008 visual-studio
source share
2 answers

the one style that I used adds space to the # tag, like this

 void Func () { int i = 3; # if DEBUG ... # endif for ( int j = 0; j < i; j++ ) { ... } } 

.. the if block looks like it is correctly aligned with the code, and the re-formatting code does not move the preprocessor tags.

+2
source share

Under Tools / Options, expand Text Editor / C # / Tabs. On this settings page, change the indentation from Smart to Block. This will stop the indentation of the preprocessor lines with the trade-off of losing other functions. I'm not good enough at this setting to tell you what other formatting you will lose, but it gives a general idea: http://www.blackwasp.co.uk/VSTabs.aspx

0
source share

All Articles