Здравствуйте, md55, Вы писали:
Ну лови первую прикидку.
На вход подается solution, CLR-имя класса и имя метода
void PrintUsagesOfMethod(ISolution solution, string className, string methodName)
{
// Находим класс по имени
IDeclarationsCache cache = PsiManager.GetInstance(solution).GetDeclarationsCache(DeclarationsCacheScope.SolutionScope(solution, true), true);
ITypeElement @class = cache.GetTypeElementByCLRName(className);
// Находим в классе все методы с заданным именем
List<IDeclaredElement> methods = new List<IDeclaredElement>();
foreach (IMethod method in @class.Methods)
{
if (method.ShortName == methodName)
methods.Add(method);
}
// Находим все использования методов
List<IReference> usages = new List<IReference>();
PsiManager.GetInstance(solution).Finder.FindReferences(methods,
SearchDomainFactory.Instance.CreateSearchDomain(solution, false),
FindResultConsumers.ConsumeReferences(usages),
NullProgressIndicator.INSTANCE);
// Собираем имена классов,внутри которых есть вызовы метода
Dictionary<string, object> classNames = new Dictionary<string, object>();
foreach (IReference usage in usages)
{
ITypeDeclaration declaration = usage.GetElement().GetContainingElement<ITypeDeclaration>(true);
if (declaration != null)
{
ITypeElement typeElement = declaration.DeclaredElement;
if (typeElement != null)
classNames[typeElement.CLRName] = null;
}
}
// печатаем в консоль найденное
foreach (string s in classNames.Keys)
Console.Out.WriteLine(s);
}