Mat*_*Mut 6 visual-studio visual-studio-2019
我想在 Visual Studio 中使用 Microsoft 的自定义文件嵌套选项来嵌套实现类文件及其“父”接口,因此在本示例中,我希望在解决方案资源管理器中ReportRepository.cs嵌套出现IReportRepository.cs。所有存储库都应该如此。

我已经在.filenesting.json解决方案的根目录中创建了该文件,但我不知道如何使用它并且文档非常稀疏。
有谁知道我如何在 Visual Studio 2019 中实现这一目标?
据我所知,不可能按前缀分组。您只能按扩展名或后缀或整个文件名进行分组。
这意味着您无法为此定义规则。但是有2个选择:
要为每个文件定义规则,您将使用fileToFile提供程序。这看起来像这样:
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"fileToFile": {
"add": {
"IInvestigationRepository.cs": [ // Parent file
"InvestigationRepository.cs" // Nested file
],
"IReporterRepository.cs": [ // Parent file
"ReporterRepository.cs" // Nested file
]
...
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者,如果第一个选项不符合您的喜好,您可以为文件使用不同的命名方案,并让类保留其旧名称。
然后你可以fileSuffixToExtension像这样使用提供者:
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"pathSegment": {
"add": {
".DefaultImplementation.cs": [
".cs"
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这将映射
IInvestigationRepository.DefaultImplementation.cs到IInvestigationRepository.cs,IReporterRepository.DefaultImplementation.cs到 IReporterRepository.cs等等。
这也将使您的文件的目的更清晰,因为仅具有相同的名称并不能告诉您它对接口做了什么,只是与接口有关。
如果您不想使用符号 with.并且更喜欢使用-,则可以通过替换"pathSegment"为"fileSuffixToExtension",并替换".DefaultImplementation.cs"为"-DefaultImplementation.cs"
小智 6
我们在 .csproj 文件中使用以下模式来自动嵌套混凝土及其接口(如果它们位于同一目录中)。
<ItemGroup>
<Compile Update="**\*.cs">
<DependentUpon>$([System.String]::Copy(I%(Filename).cs))</DependentUpon>
</Compile>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我知道问题是使用 Visual Studio 中的自定义嵌套选项;然而,在微软添加前缀功能之前,这种方法就可以发挥作用。
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |