views:

130

answers:

3

I've never really been a big fan of the way most editors handle namespaces. They always force you to add an extra pointless level of indentation.

For instance, I have a lot of code in a page that I would much rather prefer formatted as

namespace mycode{

class myclass{
  void function(){
    foo();
  }
  void foo(){
    bar();
  }
  void bar(){
    //code..
  }

}

}

and not something like

namespace mycode{

  class myclass{
    void function(){
      foo();
    }
    void foo(){
      bar();
    }
    void bar(){
      //code..
    }

  }

}

Honestly, I don't really even like the class thing being indented most of the time because I usually only have 1 class per file. And it doesn't look as bad here, but when you get a ton of code and lot of scopes, you can easily have indentation that forces you off the screen, and plus here I just used 2-space tabs and not 4-space as is used by us.

Anyway, is there some way to get Visual Studio to stop trying to indent namespaces for me like that?

+2  A: 

It's a hack, but here goes:

namespace mycode{ 
#if 0
}
#endif

class myclass{
    ...
Mark Ransom
I should've added "without really bad hacks" to my question :)
Earlz
Heh ... that is pretty good.
AdamBT
A: 

Try Tools, Options, Text Editor, C#, and hunt around for something that matches. If you don't find it, then you can't fix it.

My advice would be to put curly braces on their own line and not try to fight the editor.

Steven Sudit
I'd be interested in hearing why you thought this should be downvoted.
Steven Sudit
+1  A: 

Under "Tools" --> "Options" choose Text Editor --> C# --> Tabs

You can choose "none" for indenting.

You can also change the indent size.

I don't believe there is a way to just change it for namespace and/or class.

AdamBT
I like the auto-indenting, just not for namespaces...
Earlz
I think you are out of luck then ... with VS anyways
AdamBT
I would go with Ransom's answer then
AdamBT