16

Possible Duplicate:
How to force indentation of C# conditional directives?

Say I want to type this in Visual Studio:

    class Program
    {
        private const Byte NUM_THREADS =
        #if DEBUG
            1;
        #else
            8;
        #endif
    }

If I simply type it out (i.e. not manually fix any indentation), Visual Studio will format it like this:

    class Program
    {
        private const Byte NUM_THREADS =
#if DEBUG
 1;
#else
        8;
#endif
    }

Is there anything I can do so it automatically indents so it looks like the first example?

Community
  • 1
  • 1
David S.
  • 5,965
  • 2
  • 40
  • 77
  • What do you mean by "simply type it out"? Do you have some kind of auto-formatting mode turned on? – Greg Hewgill May 11 '12 at 08:54
  • @GregHewgill I mean typing and only adding new lines myself, but not pressing tab to add any manual indentation. – David S. May 11 '12 at 08:55
  • 2
    Visual Studio Tools | Option => Text Editor => C# => Formatting has a large number of options, but it looks like pre-processor definitions are always hung to the left (except for #region). – iCollect.it Ltd May 11 '12 at 09:26

2 Answers2

1

Unfortunately, there is no way to have preprocessor commands follow the code indentation. Wish it did though. :(

It looks like the reason is previous compilers barfed at spaces that appeared before the commands, according to: Indenting #defines

Community
  • 1
  • 1
Nyaarium
  • 1,540
  • 5
  • 18
  • 34
-2

Go to Edit menu => Format Document OR Press short cut key Ctrl+K,Ctrl+D (In short Ctrl+K+D) This short cut you can use .html, .aspx. .cs etc...

Ryan Gates
  • 4,501
  • 6
  • 50
  • 90
A.D.K
  • 27
  • 3