I'm using VS2010 with Resharper 5.1.
I have two projects, a library project (Lib) and an application project (App), App references Lib.
Lib contains a class X which is used in both App and Lib. In App i now want to replace all usages of X with class Y. In my case Y is unrelated to X, but it could inherit from X if it makes refactoring easier.
My current plan to use the "Find usages" feature, group by project and change the usages one by one. Is there an easier/automated way to do this?
Structural Search and Replace is your friend here. You get to it through ReSharper | Find | Search with Pattern...
.
X
, name it TX
.$TX$
X
Y
ReSharper will show you all the mentions of X
it wants to replace - ensure the checkbox at the top of the tree is checked, then click Replace.
edit
It is indeed by using a type placeholder in our Find pattern that ensure that only references to the type X
, rather than anything else named X
, are renamed.
If you would prefer to end up with
using A.B.C;
/* later */
Y obObject = ...
rather than
A.B.C.Y myObject
I think you can achieve this through:
ReSharper | Options
, Tools | Code Cleanup
, define a new profile which has just "Optimize 'using' directives" checkedReSharper | Options
, Languages | C# | Namespace Imports
add A.B.C
to "Namespaces that should always be imported`ReSharper | Tools | Cleanup Code
using the profile you just definedA.B.C
from the namespaces list you added it toalthough this will also clean up all other using
s, which might make the version control diff a bit larger than you want.
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