This is a good one!
Every one knows that when you add a new class to a project it is private by default, but still when you compile for the first time, the compilation fails and only then you remember to add the “public” before the class name. Tired of this? Here’s what you do in order to get Visual Studio to create the class as Public by default.
Go over to “Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033″, you will find a file called Class.zip, inside the .zip file open the file called Class.cs, the content of the file looks like this:
using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ == 3.5)using System.Linq; $endif$using System.Text; namespace $rootnamespace$ { class $safeitemrootname$ { } }
   All you need to do is add “Public” before the class name. The outcome should look like this:
using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ == 3.5)using System.Linq; $endif$using System.Text; namespace $rootnamespace$ { public class $safeitemrootname$ { } }
One last thing you need to do is flush all the Templates Visual Studio is using, and make him reload them. The command for that is ( it takes a while so hold on):Â
devenv /installvstemplates
And that’s it, no more private classes by default. Of course you can also add internal or whatever you want.
Enjoy
Amit
By denis.gz on May 15, 2008 | Reply
This is also the place to add a standard header to sources files, like copyright information and SVN $Id$ tag, so you don’t have to add manually - saves time.