How to invert #if directives in code?

Possible duplicate:
How to indent C # conditional directives?
Can visual studio automatically specify indent / format formatting?

The following code example has the #if directive, but note the absence of indentation:

  else { #if DEBUG Debug.Print(ex.Message); #endif return null; } 

I know this is probably true for some kind of pure development practice, but to be honest, in VS.NET I don't care, and I would prefer it to match my code. Is there a way to allow directives # automatically backtrack inside a line with the rest of the code in VS.NET?

Thanks!

+8
c # visual-studio
source share
3 answers

I tried to find something here:

Option β†’ Text Editor β†’ C #

but, unfortunately, it seems that visualstudio has nothing built-in that allows preprocessor directives to be retreated in this way. However, googling found this answer and recommends using StyleCop . Hope this helps you.

+2
source share

I'm not sure you can do this with Visual Studio natively. You may need to use the plugin like StyleCop. See http://stylecop.codeplex.com/

I understand why you want to indent because conditional directives now look pretty confusing. However, with the current indentation, the advantage is that it is easy to see who reads your code. Since conditional directives can greatly alter the flow of your code, this may be fine, as it is now. Otherwise, you have plugin options :)

+3
source share

I don’t know anything, but # pragmas should not be indented, since they are not affected by the code. This is normal for Debug.Print indents, of course.

+2
source share

All Articles