codemaid
codemaid copied to clipboard
Feature request: "Fix" namespaces (sync with folder structure)
First of all, congrats on the awesome project!
It'd be great to have an option (in the context menu or even automatically when saving a file/project/solution) to sync namespaces based on folder structure, being able to skip files by applying filters (e.g., file name, type name, file extension, etc.).
Tks!
From your idea, I will contribute a part to this project, you will wait :) Hope to accept pull request
Thanks for the suggestion and kind comments @chlopes
being able to skip files by applying filters (e.g., file name, type name, file extension, etc.).
Can you please expand on this part a little?
Can you please expand on this part a little?
Sure!
The idea behind the filter is to cover scenarios where the namespace does not follow the folder structure. This pattern seems to have become more popular with .NET Core / ASP.NET Core, which extensively uses extension methods on their abstractions.
An example of this pattern is the sponsor class MvcServiceCollectionExtensions, which is located on Microsoft.AspNetCore.Mvc.dll (.NET 5) and is defined in the same namespace as the class it extends (Microsoft.Extensions.DependencyInjection.IServiceCollection).
namespace Microsoft.Extensions.DependencyInjection
{
public static class MvcServiceCollectionExtensions
{
...
public static IMvcBuilder AddControllers(this IServiceCollection services)
{
...
}
...
}
}
https://github.com/dotnet/aspnetcore/blob/0bc3c376f0cd14335e8b3afca69596acabeb1f80/src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs#L87
This pattern complies with the FDG, which states as follow:
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/extension-methods
I don't know exactly which types of filters are possible to be offered to the user (by file name with or without extension, by type name, by access modifiers, etc.), but probably the only really needed is a filter by filename (regex, globbing, etc.). With that, the user could set a filter to skip files with suffix Extensions and the pattern above would not be affected by the sync, which is the desired behavior.
Another possible inspiration for this feature is Adjust Namespaces from ReSharper.