Class modifier for auto-generated classes

When I add a new class to the project, the class modifier / qualifier specifier for the newly created class in Visual Studio is excluded, thereby making it internal.

Is there a way that I can specify in Visual Studio settings when whenever I ask to create a new class, create a class public?

I looked at the menu Tools-> Options, but could not find anything. I assume it could be in the Templates folder in the My Documents \ Visual Studio xxxx folder .

+3
source share
4 answers

Yes, you can change file templates (or just provide additional file templates) like this . However, before you do this, I asked myself the question: is it really a lot of effort to add the desired availability? I tend to err on the pragmatic side when it comes to this ... if I wanted to have significantly different patterns, I could do it. Otherwise ... meh.

+3
source

You will need to create your own template for this, or use code snippets, or perhaps a tool like ReSharper, which has its own fragment mechanism.

, , . , . internal .

+2
+2

, :

  • ( )
  • private ( )

, ( , ).


, , , ( ):

** C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE **

. ( ): C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

Class.cs. , , :

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;

namespace $rootnamespace$
{
    class $safeitemrootname$
    {
    }
}

:

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;

namespace $rootnamespace$
{
    public class $safeitemrootname$
    {
    }
}
+2

Source: https://habr.com/ru/post/1756619/


All Articles