Domanda

I need to replace all the ocurances of obj.Method1() to obj.Method2() where obj is an instances of the same class. Does ReSharper or VS2010 allow this?

È stato utile?

Soluzione

I'd cheat - Do a 3-point symbolic rename (Right-click->Rename on a method name)

  • Method1 -> Temp
  • Method2 -> Method1
  • Temp -> Method2

None of this will change code functionality but will update all your code to use the correct name, except the methods themselves are now named incorrectly - simply rename the methods to by hand and voila - A little bit hacky but fast and effective.

This does rely on all method calls being in managed code (so that VS knows how/what to rename). If you have XML comments, C# rename handles this well but VB doesn't - I assume since you mention ReSharper, you're using C#?

This also assumes the method signatures are identical (if not, get ready for a lot of copy/pasting)

Altri suggerimenti

You could write a ReSharper Replace Pattern (ReSharper->Tools->Pattern Catalog, Add Pattern) like so:

enter image description here

where the type of expression obj needs to be changed to your class (that contains Method1).

Then press Save and thereafter press Search now to get all Method1() calls:

enter image description here

Then click Replace and all Method1 calls are type-safely replaced to Method2.

Make body of Method1 like this

public void Method1(...) { return Method2(...); }

And invoke refactoring "Inline method" on Method1.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top