我正在尝试使用Resharper SDK插件创建自定义导航到插件。当我站在自己的类型上时,已经设法获取了IDeclaredElement或ITypeElement
var referenceName = dataContext.GetSelectedTreeNode<IReferenceName>();
var declaration = referenceName?.Reference.Resolve()?.DeclaredElement as ITypeElement;
if (declaration != null)
{
//TODO: Find all usages here and check if my type is used as single argument to a method (Visitor pattern)
}
SDK文档确实很稀疏,我在该主题上找不到任何东西。谢谢
答案 0 :(得分:0)
经过反复试验,我找到了一个可行的解决方案。 IFinder.FindAllReferences
var foundMethods = declaration
.GetPsiServices()
.Finder
.FindAllReferences(declaration)
.Select(r => ((r.GetTreeNode().Parent as IUserTypeUsage)?
.Parent as IRegularParameterDeclaration)?
.Parent as IFormalParameterList)
.Where(list => list != null && list.ParameterDeclarations.Count == 1)
.Select(m => m.Parent as IMethodDeclaration)
.Where(m => m != null)
.ToList();
完整代码here