How do you default a new class to public when creating it in Visual Studio?

后端 未结 7 848
不知归路
不知归路 2020-11-28 02:54

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)

7条回答
  •  时光说笑
    2020-11-28 03:21

    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) 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).

    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) 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.

提交回复
热议问题