roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

New refactoring rename namespace by folder structure

Open martinsura opened this issue 8 years ago • 7 comments

Hello,

Nice extensions. Is here any plan to support rename namespace by folder structure?

Thanks

martinsura avatar Feb 21 '17 16:02 martinsura

This requires access to "default namespace" property, which is not currently supported.

See https://github.com/dotnet/roslyn/issues/3798.

josefpihrt avatar Mar 01 '17 22:03 josefpihrt

+1

Can you work it out based on the folder structure, up to the point of hitting a project file, like a .csproj in the case of C#?

It would unblock this feature, and for 90% of cases I'm pretty sure that would work.

kieronlanning avatar Apr 14 '17 09:04 kieronlanning

@kieronlanning I'm afraid don't understand your proposal. How do you want to obtain default namespace?

josefpihrt avatar Apr 14 '17 13:04 josefpihrt

The default namespace is usually the project name, or in the .csproj it has RootNamespace in a PropertyGroup if it's been overridden.

kieronlanning avatar Apr 15 '17 09:04 kieronlanning

That would mean to read and parse csproj file every time a refactoring is computed (every time before it is displayed in the context menu).

josefpihrt avatar Apr 18 '17 19:04 josefpihrt

According to dotnet/roslyn#31253, it seems the roslyn team is working on this very refactoring (a basic version of it works in VisualStudio 2019 RC). It does not seem as if they are providing a warning for it though (at least not at the moment).

Would it be possible to add an analyzer to Roslynator that provides the warning (If i understand correctly, the default namespace is now exposed in the project system dotnet/roslyn#30998)? The refactoring can be used from Rosyln itself i guess.

felixhirt avatar Feb 28 '19 10:02 felixhirt

Uh, im afraid i was a bit too eager. It seems there is still no way to get the project context from a code analyzer. But maybe the roslyn team will turn the refactoring into an analyzer

felixhirt avatar Mar 03 '19 20:03 felixhirt