Find all static method calls in a class

Hello,

I have a class that calls static methods in other classes.  I want to delete or replace all these calls to static methods.  How do I write resharper code to return a list of all static method invocations in a class?

Thanks.

1 comment
Comment actions Permalink
If you can get hold of all ITypeElement objects in your solution, then each ITypeElement has a Methods Collection of IMethodObjects. Each IMethod object has an IsStatic property, which means that you can find all static methods in the solution.

Next you need to find all references to static methods occurring in the class you want to refactor. For each ITypeElement you can find all the usages of each method using the following code (which assumes that you have an ISolution in a variable called Solution and your IMethod is stored in a variable called elementToFindReferencesTo)

 SearchDomainFactory searchDomainFactory = _solution.GetComponent<SearchDomainFactory>();
var searchResultsConsumer = new SearchResultsConsumer();
 
            
_solution.GetPsiServices().Finder.FindReferences(                 elementToFindReferencesTo,                 searchDomainFactory.CreateSearchDomain(_solution, false),                 searchResultsConsumer,                 NullProgressIndicator.Instance,                 false);

var occurrences = searchResultsConsumer.GetOccurences()

occurrences is a collection of IOccurence which has a TypeElement property which you can check to see if it's in your class.

0

Please sign in to leave a comment.