I want to use Microsoft's custom file nesting option in Visual Studio to nest implementation class files with their "parent" interfaces, so in this example, I would like ReportRepository.cs
to appear nested under IReportRepository.cs
in the solution explorer. The same should be for all repositories.
I have created the .filenesting.json
file in the root of the solution, but I have no idea how to use it and documentation is very sparse.
Does anyone know how I can achieve this in Visual Studio 2019?
As far as I can gather it is not possible to group by prefixes. You can only group by extensions or suffixes, or entire file names.
This means you can't define a rule for this. However there are 2 options:
To define a rule for each file you would use the fileToFile
provider.
This would look like so:
{
"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
]
...
}
}
}
}
}
Alternatively, if the first option is not to your liking, you could use a different naming scheme for your files, and let the classes keep their old names.
Then you could use the fileSuffixToExtension
provider like such:
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"pathSegment": {
"add": {
".DefaultImplementation.cs": [
".cs"
]
}
}
}
}
}
This would map
IInvestigationRepository.DefaultImplementation.cs
to IInvestigationRepository.cs
,IReporterRepository.DefaultImplementation.cs
to IReporterRepository.cs
and so on.
This would also make the purpose of your files clearer, as just having the same name doesn't tell you what it's doing with the Interface, just that is has something to do with it.
If you don't want to use a notation with .
and would prefer to use -
, you can do that by replacing "pathSegment"
with "fileSuffixToExtension"
, and replacing ".DefaultImplementation.cs"
with "-DefaultImplementation.cs"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With