How to Get Visual Studio to Create New Classes Public by Default

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.

(Source)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: