Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to get VS 2008 to stop forcing indentation on namespaces?

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?

like image 943
Earlz Avatar asked Feb 08 '10 22:02

Earlz


People also ask

Should namespaces be indented?

The contents of namespaces should not be indented.

Does C# require indentation?

Even though a language like C# has explicit scoping and statement termination with its curly brackets and semicolons, indentation still matters. It doesn't matter to the compiler, but it matters to humans.


1 Answers

It's a hack, but here goes:

namespace mycode{ 
#if 0
}
#endif

class myclass{
    ...
like image 161
Mark Ransom Avatar answered Oct 25 '22 20:10

Mark Ransom