提问人:JuanF 提问时间:9/14/2023 最后编辑:JuanF 更新时间:9/29/2023 访问量:93
Visual Studio 2022(或 ReSharper)是否可以显示按执行顺序排序的所有成员引用的列表或树?
Can Visual Studio 2022 (or ReSharper) show a list or tree of all references to a member sorted by order of execution?
问:
我正在重写一个类中的代码,该类在许多不同的私有方法中更改私有状态,并且很难跟踪该类的每个成员最终将具有什么值。
赋值大多独立于其先前的值以及彼此之间的值,因此许多成员的状态最终由称为 last 的任何赋值决定。它们都是布尔值。
这是一个示例(在 VB 中,但同样适用于 C#),展示了最简单的情况,没有任何分支或具有多个引用的二阶方法。假设该方法是入口点:SetVisibilities
Dim isAVisible As Boolean
Dim isBVisible As Boolean
Dim isCVisible As Boolean
Private Sub SetVisibilities()
ChangeVisibilitiesFirst()
ChangeVisibilitiesSecond()
' This is the last change for C but is the earliest reference in the file (by line number)
isCVisible = False
End Sub
Private Sub ChangeVisibilitiesSecond()
isAVisible = False
isBVisible = True
isCVisible = True
End Sub
' This gets called first but is defined later in the file
Private Sub ChangeVisibilitiesFirst()
isAVisible = True
isBVisible = False
isCVisible = True
End Sub
在进一步简化每个可见性评估之前,我想首先安全地将每个成员的所有状态更改转换为这样的内容:
Private Sub SetVisibilities()
isAVisible = GetVisibilityForA
isBVisible = GetVisibilityForB
isCVisible = GetVisibilityForC
End Sub
Private Function GetVisibilityForA() As Boolean
Dim response As Boolean
response = True ' From: ChangeVisibilitiesFirst()
response = False ' From: ChangeVisibilitiesSecond()
Return response
End Function
Private Function GetVisibilityForB() As Boolean
Dim response As Boolean
response = False ' From: ChangeVisibilitiesFirst()
response = True ' From: ChangeVisibilitiesSecond()
Return response
End Function
Private Function GetVisibilityForC() As Boolean
Dim response As Boolean
response = False ' From: ChangeVisibilitiesFirst()
response = True ' From: ChangeVisibilitiesSecond()
response = False ' From: SetVisibilities()
Return response
End Function
我的手动方法是从入口点 () 开始,然后首先深入到每个方法调用和每行代码,直到我找到一个赋值,然后将该赋值附加到该特定成员的定制新方法。如果涉及一些分支,我也会附加它。SetVisibilities
到目前为止,我已经使用了 Visual Studio 2022 的“查找所有引用”和“查看调用层次结构”,其中第一个按它们在文件中找到的顺序列出了所有引用,虽然调用层次结构很接近,但很难解析,因为它在通常如下所示的树中表示:
- isCVisible - ChangeVisibilitiesSecond(), calls isCVisible on line 15 - SetVisibilities(), calls ChangeVisibilitiesSecond() on line 7 - SetVisibilities(), calls isCVisible on line 5 - ChangeVisibilitiesFirst(), calls isCVisible on line 6 - SetVisibilities(), calls ChangeVisibilitiesFirst() on line 5
虽然我更希望看到的是这样的:
- SetVisibilities() - ChangeVisibilitiesFirst() - calls isCVisible on line 22 - ChangeVisibilitiesSecond() - calls isCVisible on line 15 - calls isCVisible on line 9
答: 暂无答案
评论