Visual Studio 2005 – Make new classes public by default

Thanks to a co-worker, Chris Dereadt (thanks Chris), I have finally squashed one of my pet peeves with Visual Studio 2005.

To make all new classes public edit the Class.cs file in the following location:

C:Program FilesMicrosoft Visual Studio 8Common7IDEItemTemplatesCacheCSharp1033
(the drive is dependent on where you installed Visual Studio)

Add the word “public” in front of the class definition and from now on when you right-click a project and choose “Add Class” it will be a public class.



Thanks again Chris.  You need to start blogging. =)

About Jason Meridth

Continuously learning software developer trying to not let best be the enemy of better
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

5 Responses to Visual Studio 2005 – Make new classes public by default

  1. Don’t get me wrong the reason I make my classes public by default is that I practice Test Driven Development (TDD) and for NUnit to see my Test Fixture it has to be public.

    Before any of you starti commenting on class exposure. =)

  2. David Dobbins says:

    Although I haven’t yet had the opportunity to try the “friend assemblies” feature (InternalsVisibleToAttribute), it looks to be well suited for this.

  3. Joe Ocampo says:

    Very nice find.

  4. Thank you David.

    This will by no means remove the need for mocking.
    According to the MSDN information:

    “…private types and private members will remain inaccessible”

  5. David Dobbins says:

    Ah, I was relying on the “…all nonpublic types in an assembly are visible to another assembly” that is stated on the page documenting the attribute itself:

    My (very limited) testing so far indicates that privates do indeed remain private.