C#10 介绍文件范围的命名空间 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces,我想在 Visual Studio 的类模板中使用它。我已将“类”模板文件更新为以下内容:
namespace $rootnamespace$;
class $safeitemrootname$
{
//I put this comment here to make sure it's using the right file
}
但是当我创建一个新的空类时,我得到了这个自动生成的代码:
namespace ProjectName
{
internal class Class1
{
//I put this comment here to make sure it's using the right file
}
}
我需要做什么才能使空类的自动生成代码看起来像这样?
namespace ProjectName;
internal class Class1
{
}
作为参考,我使用的是 Visual Studio 2022 Professional,我的项目使用的是 C#10 和 .NET 6。
我正在修改的类模板文件的位置是:C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
您必须将项目的 editorconfig 设置为首选文件范围的命名空间。
-
右键单击您的项目。选择“添加”→“新项目”
-
选择“编辑器配置文件(.NET)”
-
双击新的 editorconfig 文件。在“代码样式”选项卡中,将“命名空间声明”设置为“文件范围”
代码模板现在将按预期工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)