我正在嘗試使用 Resharper SDK 插件創(chuàng)建自定義導(dǎo)航插件。當(dāng)我站在我的類型上時,我已經(jīng)設(shè)法獲得了 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 文檔非常少,我找不到任何關(guān)于這個主題的內(nèi)容。謝謝
1 回答

繁花如伊
TA貢獻2012條經(jīng)驗 獲得超12個贊
經(jīng)過反復(fù)試驗,我找到了一個可行的解決方案。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();
完整代碼在這里
- 1 回答
- 0 關(guān)注
- 87 瀏覽
添加回答
舉報
0/150
提交
取消