查找 ITypeElement 或 IDeclaredElement 与 Resharper SDK 的用法
Find usages of ITypeElement, or IDeclaredElement with Resharper SDK
我正在尝试使用 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 文档非常少,我找不到任何关于该主题的内容。谢谢
经过反复试验,我找到了可行的解决方案。 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
我正在尝试使用 Resharper SDK 插件创建自定义导航插件。当我站在我的类型上做
时,我已经设法获得了 IDeclaredElement 或 ITypeElementvar 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 文档非常少,我找不到任何关于该主题的内容。谢谢
经过反复试验,我找到了可行的解决方案。 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