在Visual Studio中创建新类时,如何将其默认为public? [英] How do you default a new class to public when creating it in Visual Studio?

查看:720
本文介绍了在Visual Studio中创建新类时,如何将其默认为public?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我右键单击C#Visual Studio项目的解决方案并选择添加...">类..."时,它将创建一个没有公共修饰符的类.如何使Visual Studio(2008)将类默认设置为公共类?

When I right click in the Solution of a C# Visual Studio project and select Add... > Class... it creates a class without a public modifier. How do I get Visual Studio (2008) to default the class to a public class?

推荐答案

您需要修改C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033中的文件.

You need to modify the file located in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033.

Visual Studio 2010(10.0)及以下版本:其中有一个名为Class.zip的zip文件.解压缩此文件,编辑文件以放入您的public关键字,然后重新打包(确保备份了原始文件).

Visual Studio 2010 (10.0) and below: There is a zip file in there called Class.zip. Unpack this, edit the file to put in your public keyword then re-pack it (make sure you backup the original).

此后,通过打开Visual Studio命令外壳并执行以下命令,确保VS重建其缓存(只是解压缩到C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache中目录中的zip文件):

After this, make sure VS rebuilds it's cache (which is just the zipfiles unzipped into directories in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache) by opening a Visual Studio command shell and execute the following command:

devenv /installvstemplates

Visual Studio 2012(11.0)及更高版本: 请参见 @JochemKempe的答案,因为现在只需通过编辑单个文件(无需解压缩或重新压缩).

Visual Studio 2012 (11.0) and up: See the answer by @JochemKempe, as it's much easier to change this now, just by editing a single file (no unzipping or rezipping).

更新:在进行任何编辑之前,请不要忘记以管理员权限打开首选的文本编辑器.

UPDATE: Don't forget to open your preferred text editor with admin privileges before you do any edit.

这篇关于在Visual Studio中创建新类时,如何将其默认为public?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆