I have a superclass which is inherited by many subclasses. I would like to find all calls to a certain method in this superclass which originate from instances of a specific inheriting class. Is this possible in VS2012 (with Resharper 7.1)?
Code example:
public class Super
{
public void foo(Arg a)
{
...
}
}
public class Sub1 : Super
{
...
}
public class Sub2 : Super
{
...
}
public class SomeClass
{
public void Run()
{
...
var sub1 = new Sub1();
sub1.foo(a);
var sub2 = new Sub2();
sub2.foo(b);
}
}
I would like to find only the call sub2.foo(b) not sub1.foo(a) in the example above.
You should be able to use Structural Search and Replace to set up a pattern to find the usages. Go to ReSharper -> Find -> Search with Pattern. Create a pattern such as $exp$.Foo($args$). Then add an "expression" placeholder for exp. You can specify what type this should be, and check the tick box to specify exact type. Here you'd enter the fully qualified type All.Your.Namespaces.Sub2. Then add an "arguments" placeholder for args. Leave everything unchecked - it will match any number of arguments. Clicking find should find all calls to Foo from any expression that matches Sub2.
来源:https://stackoverflow.com/questions/27521657/find-usages-of-inherited-method-only-from-a-specific-subclass