的Visual C#2010速成:指定新类的默认访问修饰符? [英] Visual C# 2010 Express: Specify default access modifier for new classes?
问题描述
每当我使用Visual Studio创建它没有访问修饰符创建它们2010速成C#新类。 9倍的10我希望我的新类是公共的。怎样才可以有Visual Studio中创建空类模板在默认情况下公开的修改?
Whenever I create new classes using Visual Studio 2010 Express C# it creates them with no access modifier. 9 times out of 10 I want my new classes to be public. How can I have Visual Studio create empty class templates with the "public" modifier by default?
推荐答案
关键是要建立一个新项目的模板命名的类。然后,当你添加>新类,你的模板将被默认,而不是内置的类模板中选择。 (我不知道这种行为是有保障但它的作品在我的机器(TM))。要创建模板:
The trick is to create a new item template named Class. Then when you do Add > New Class, your template will be selected by default rather than the built-in Class template. (I am not sure if this behaviour is guaranteed but it Works On My Machine (TM).) To create the template:
- 右键单请在您的项目,然后选择添加>类。您可以接受默认名称(1级) - 这只是一个临时文件
- 通过添加public修饰符修改生成的类,例如。保存一切。
- 选择文件>导出模板。
- 选择项目模板,并指定相关的文件(将Class1.cs)。
- ,直到你的模板选项页点击下一步。对于模板名称,输入类。
- 单击Finish(完成)。
- 删除临时Class文件。
- Right-click in your project and choose Add > Class. You can accept the default name (Class1) -- this is just a temporary file.
- Modify the generated class as, for example by adding the public modifier. Save everything.
- Choose File > Export Template.
- Choose Item Template and specify the relevant file (Class1.cs).
- Click Next until you get to the Template Options page. For the template name, enter Class.
- Click Finish.
- Delete the temporary Class1.cs file.
现在做一个添加>类,你会看到你的类模板中使用默认的而不是内置于一体。
Now do an Add > Class and you should see your Class template being used by default instead of the built-in one.
这篇关于的Visual C#2010速成:指定新类的默认访问修饰符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!