使用 Resharper SDK 查找 ITypeElement

我正在尝试使用 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 文档非常少,我找不到任何关于这个主题的内容。谢谢


江户川乱折腾
浏览 90回答 1
1回答

繁花如伊

经过反复试验,我找到了一个可行的解决方案。IFinder.FindAllReferencesvar foundMethods = declaration&nbsp; &nbsp; .GetPsiServices()&nbsp; &nbsp; .Finder&nbsp; &nbsp; .FindAllReferences(declaration)&nbsp; &nbsp; .Select(r => ((r.GetTreeNode().Parent as IUserTypeUsage)?&nbsp; &nbsp; &nbsp; &nbsp; .Parent as IRegularParameterDeclaration)?&nbsp; &nbsp; &nbsp; &nbsp; .Parent as IFormalParameterList)&nbsp; &nbsp; .Where(list => list != null && list.ParameterDeclarations.Count == 1)&nbsp; &nbsp; .Select(m => m.Parent as IMethodDeclaration)&nbsp; &nbsp; .Where(m => m != null)&nbsp; &nbsp; .ToList();完整代码在这里
打开App,查看更多内容
随时随地看视频慕课网APP