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.
A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass. A nested class has access to all the private members of its enclosing class—both fields and methods.
A subclass also inherits variables and methods from its superclass's superclass, and so on up the inheritance tree.
A subclass is the same as an inherited class. In example A, bar is an inner class.
lang. Object is the root of a hierarchy of classes. The subclass inherits state and behavior in the form of variables and methods from its superclass. The subclass can just use the items inherited from its superclass as is, or the subclass can modify or override it.
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
.
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