Refactoring class location

  • Thread starter Thread starter Kowalski
  • Start date Start date
K

Kowalski

I want to move a class from one namespace to another.

Do you know any refactoring tool with such a feature?
 
Am i missing some important concept here? All you need to do is retype a new
namespace over the existing namespace declaration at the top of the class...
Peter
 
On re-reading this, I'm guessing that this revolves around a potential
misunderstanding between namespaces and assemblies.
Namespace is just a logical way of grouping related classes together. They
don't even need to be in the same physical compiled assembly.
I'm guessing that you are looking for something to move a class into a
separate physical assembly (not namespace)?
Peter
 
Peter Bromberg said:
Am i missing some important concept here? All you need to do is retype a new
namespace over the existing namespace declaration at the top of the class...

And anything that uses it needs to make sure they use the new namespace
too.

Oh, and to keep things consistent you'll want to move the file too.

It's handy to get a tool to do these things for you :) My guess is that
ReSharper is likely to be capable of this, but I haven't checked.
 
Peter Bromberg [C# MVP] napisał(a):
On re-reading this, I'm guessing that this revolves around a potential
misunderstanding between namespaces and assemblies.
Namespace is just a logical way of grouping related classes together. They
don't even need to be in the same physical compiled assembly.
I'm guessing that you are looking for something to move a class into a
separate physical assembly (not namespace)?

No, I don't want to play with assemblies.
Just the simple case with namespaces and even in one project.

Example: move a class A.B.C.MyClass into E.F.MyClass.
 
Jon Skeet [C# MVP] napisał(a):
And anything that uses it needs to make sure they use the new namespace
too.

That's the point.
Oh, and to keep things consistent you'll want to move the file too.
Optionally.

It's handy to get a tool to do these things for you :) My guess is that
ReSharper is likely to be capable of this, but I haven't checked.

Thanks, I'll take a look.
 
Kowalski said:
I want to move a class from one namespace to another.

Do you know any refactoring tool with such a feature?

You may have to use search and replace unfortunately. Many issues could
arise like namespace conflicts if the same class name is used in multiple
namespaces. The refactoring tool would need to know to handle changing
"using" statements, or to update references to fully qualified names and
remove using statements etc. Would be interested to know if any of the
refactoring tools handle this.
I would go one of two routes. 1) Change the namespace and then lean on the
compiler. 2) Replace all references with fully qualified names. Then do a
search and replace.

PS
 
You may have to use search and replace unfortunately. Many issues could
arise like namespace conflicts if the same class name is used in multiple
namespaces. The refactoring tool would need to know to handle changing
"using" statements, or to update references to fully qualified names and
remove using statements etc. Would be interested to know if any of the
refactoring tools handle this.
I would go one of two routes. 1) Change the namespace and then lean on the
compiler. 2) Replace all references with fully qualified names. Then do a
search and replace.

I was doing almost the same thing with search and replace, sometimes
renaming namespace was helpful (VS has that).

Jon suggested "ReSharper" and it works :)
The "Move Type" function does the job.
 
Kowalski said:
I was doing almost the same thing with search and replace, sometimes
renaming namespace was helpful (VS has that).

Jon suggested "ReSharper" and it works :)
The "Move Type" function does the job.

Thanks, I will check it out.

PS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top