Поделиться через


Find potential problems in code using dependency graphs

You can run analyzers on dependency graphs in Visual Studio Ultimate to help you identify code that might be overly complex or that might need improvement. For example, you can use these analyzers to perform the following tasks:

To find code that has

Examine these areas to see whether

Loops or circular dependencies

You can simplify them and consider whether you can break these cycles.

Too many dependencies

They are performing too many functions or to determine the impact of changing these areas. A well-formed dependency graph will show a minimal number of dependencies. To make code easier to maintain, change, test, and reuse, consider whether you can refactor these areas so that they are more clearly defined, or whether you can merge code that performs similar functions.

No dependencies

They are necessary or whether you should remove this code.

Running Analyzers on Dependency Graphs

  1. Make sure the graph layout is set to tree layout or Quick ClustersQuick Clusters button on graph toolbar layout. For more information about how to change the graph layout, see How to: Browse and Rearrange Dependency Graphs.

  2. If the Legend box is not visible, open the shortcut menu for the diagram, and then choose Show Legend.

  3. In the Legend box, choose Add, choose Analyzers, and then and then choose one of the following analyzers:

    Analyzer

    To identify nodes that

    Circular Reference

    Have circular dependencies on each other.

    Note

    Circular dependencies that are in the Generics group are not shown on the graph when you expand the group.

    Find Hubs

    Are in the top 25% of highly-connected nodes

    To hide all other nodes on the graph

    • Open the shortcut menu for the graph, choose Selection, and then choose Hide Unselected.

      The graph hides the unselected nodes, and the analyzer identifies new nodes as hubs.

    Unreferenced Nodes

    Do not have references from any other nodes.

    Warning

    Verify each of these cases before assuming that the code is not used. Certain dependencies such as XAML dependencies and run-time dependencies cannot be found statically in the code.

Dependency graph analyzers will continue to run after you apply them. If you change the graph, any applied analyzers will automatically reprocess the updated graph. To stop running an analyzer, open the shortcut menu for the analyzer in the Legend box, and then choose Delete.

Tip

If you have a very large graph, running an analyzer might cause an out of memory exception. If this occurs, edit the graph to reduce its scope or generate a smaller one, and then run the analyzer.

See Also

Concepts

Map dependencies across your code on dependency graphs