I want to move a class form one namespace to another, programmatically. This includes adjusting any dependencies the moved class had in its previous namespace.
I'm guessing that I can make use of the Roslyn project somehow, but I can't finding a starting point.
Edit:
I'm trying to implement an automatic move class refactoring on C# code. Doing it for study purposes - gathering code metrics and studying the changes before and after the refactoring process.
I can do the refactorings by hand, but was wondering If I can do it automatically. This means that I already have the refactoring candidates and their proposed move locations.
This can be used to move individual classes to a different namespace by: applying the mentioned refactoring (CTRL+. with the cursor over the namespace) These operation ensures that all references are updated accordingly. Move to namespace doesn't change references. I don't have Change namespace to, is it Enterprise only feature?
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another. A namespace definition begins with the keyword namespace followed by the namespace name as follows −.
The class names declared in one namespace does not conflict with the same class names declared in another. A namespace definition begins with the keyword namespace followed by the namespace name as follows − To call the namespace-enabled version of either function or variable, prepend the namespace name as follows −
There is no built-in support for this, so yes, you'd have to implement this yourself.
If you did want to try this, there's some high level steps you'd probably do:
You could dig through our rename code to see how we do this, but I'll warn you it's fairly complex. This refactoring is probably "medium" in terms of difficulty, so not to dissuade you but you have an uphill battle if you tried this as your first introduction to Roslyn.
(Motto: refactorings are always harder than you think they are.)
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