Can visual studio automatically indent / format preprocessing directives? [duplicate]

狂风中的少年 提交于 2019-12-30 06:02:56

问题


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?


回答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




回答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...



来源:https://stackoverflow.com/questions/10548319/can-visual-studio-automatically-indent-format-preprocessing-directives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!