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. =)
Jason Meridth: 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. =)
David Dobbins: Although I haven’t yet had the opportunity to try the “friend assemblies” feature (InternalsVisibleToAttribute), it looks to be well suited for this.
Joe Ocampo: Very nice find.
Jason Meridth: Thank you David. This will by no means remove the need for mocking. According to the MSDN information: http://msdn2.microsoft.com/en-us/library/0tke9fxk(vs.80).aspx “…private types and private members will remain inaccessible”
David Dobbins: 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: http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(VS.80).aspx My (very limited) testing so far indicates that privates do indeed remain private.