Find usages of inherited method only from a specific subclass?

两盒软妹~` 提交于 2019-12-07 02:45:51

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!