ReSharper 2016.3 Help

Exploring Type Dependency Diagram

ReSharper | Architecture | Show Type Dependency Diagram
ReSharper_ShowTypesDependencies

ReSharper allows you to visually study how types depend on each other in your solution. In the type dependency diagram, you can add any number of types from different projects or compiled assemblies and visualize different kinds of dependencies between them.

In this topic:

Building the initial diagram

There are several ways to build a new type dependency diagram:

  • Select one or more items in the Solution Explorer, Object Browser, Architecture Explorer, Class View, or Assembly Explorer window and then choose ReSharper | Architecture | Show Type Dependency Diagram in the main menu, right-click the selection, and choose Show Type Dependency Diagram, or alternatively, press Ctrl+Shift+Alt+A and then choose Show Type Dependency Diagram.
    In this case, all types declared within the selected items are added to the diagram, and aggregation, usage, and inheritance dependencies are visualized.
  • Set the caret anywhere in the editor, and choose ReSharper | Architecture | Show Type Dependency Diagram in the main menu or invoke the Inspect This command ( choose ReSharper | Inspect | Inspect This or press Ctrl+Shift+Alt+A), and then choose Show Type Dependency Diagram.
    In this case, all types from the file are added to the diagram, and aggregation, usage, and inheritance dependencies are visualized.
  • In the Architecture View, select one or more items, right-click the selection and choose Show Type Dependency Diagram in the context menu.
  • In the result list of the Go to Base Symbols, Go to Derived Symbols, Navigate To Exposing APIs or similar commands, press Alt+Num+ or click Show on Diagram /help/img/dotnet/2016.3/ThemedIcon.TypeLayoutAlt.Screen.[Gray].png
    In case of base/derived symbols, the corresponding part of the inheritance hierarchy is added to the diagram and only inheritance dependencies are visualized. In case of the exposing APIs, the diagram displays types containing methods that return the given type and only return type dependencies.
  • For the list of results shown in the Find Results window or Hierarchy window, click Show on Diagram /help/img/dotnet/2016.3/ThemedIcon.TypeLayoutAlt.Screen.[Gray].png.
    In these cases, all usages or hierarchy entries are added to the diagram, and usage/inheritance dependencies are visualized.
  • Select one or more project references, right-click the selection, and choose Show Usages on Diagram /help/img/dotnet/2016.3/ThemedIcon.TypeLayoutAlt.Screen.[Gray].png.
    In this case, usages the diagram will show usages of types from the referenced assembly in the referencing project.

The newly created project dependency diagram is displayed in a new tab of the Hierarchy window.

Note that the diagram is not synchronized with the solution, i.e. if you rename or delete types in your code, the diagram is not changed. To see whether the diagram is up to date, you can check the creation time displayed in the bottom right corner. You can also rebuild the diagram by clicking Refresh Type Dependencies /help/img/dotnet/2016.3/ThemedIcon.Refresh.Screen.[Gray].png on the toolbar.

Adjusting the view of the diagram

Type dependency diagram can be laid out in two ways:

  • Inheritance Hierarchy Layouter - this option arranges types according to their inheritance relations: the base types are moved upward.
  • Business Logic Layouter - this option arranges types according to all displayed relations between them.

You can switch between these options using the corresponding selector in the left:

Switching layout on the type dependency diagram

Diagram layout is updated automatically every time you refresh the diagram, add or remove types, or change dependency filters.

To pan and zoom the diagram, use the controls in the upper left corner of the diagram area. Alternatively, you can click anywhere in the diagram area outside the diagram items and drag while the hand cursor /help/img/dotnet/2016.3/cursor_hand.png is shown. For zooming, you can also use the mouse wheel.

The diagram layout is calculated automatically, but you can change it if necessary: all items can be moved. To move an item (a type, a dependency link, or a grouping item), first click on it to select, and then click and drag it while the cross cursor /help/img/dotnet/2016.3/cursor_cross.png is shown.

If necessary, you can collapse and expand grouping items in the diagram in one of the following ways:

  • Click on the down arrow in the left top corner of the grouping item. When collapsed, the sign changes into an up arrow and you can click on it to expand the item.
  • Select a grouping item in the diagram and press Ctrl+LeftArrow and Ctrl+RightArrow.

Adding and removing items on the diagram

At any moment, you can modify the displayed diagram so that only desired types are displayed. If necessary, you can reverse changes made in the diagram (added/removed items) step by step by clicking Undo /help/img/dotnet/2016.3/ThemedIcon.Undo.Screen.[Gray].png or pressing Ctrl+Z. To reverse the Undo commands, click Redo /help/img/dotnet/2016.3/ThemedIcon.Redo.Screen.[Gray].png or press Ctrl+Y.

To remove types and folders from the diagram, either use the cross in the right top corner of grouping items or press Delete while the items are selected. Alternatively, select items you want to keep, right-click the selection and choose Show Only Selected Items in the context menu. For multiple selection,Ctrl-click items.

There are also several ways to add items to the diagram:

  • Drag-n-drop types, folders, and projects from the Solution Explorer to the diagram.
  • Select a type in the editor and drag-n-drop the selected type to the diagram.
  • To find and add all referenced types, right-click on a type or a grouping item and choose Add all referenced types in the context menu. If you invoke this command on a grouping item (folder or project), ReSharper adds referenced types for all types that are currently shown.
  • To find and add types by name from the solution and referenced assemblies, start typing the name in the search box. You can use wildcards (e.g. the asterisk '*') and CamelHumps while typing:
    Adding types to the type dependency diagram

    Select a type and press Enter or click on it to add it to the diagram. Types highlighted with green in the drop-down are already added to the diagram. If you select such type, the diagram focus moves to it.
  • In the details pop-up, click on any related type to add it, or use the Add all used types to the diagram, Add all usages to the diagram, Add all base types, and Add all immediate inheritors links to add multiple types.

Studying specific types and containers

When a node is collapsed, you can hover a mouse over it and quickly check out what is inside. In the pop-up that appears, you can see the number of types added to the diagram within this node and all modules referenced from within this node:

Studying projects and containers

If necessary, you can click on referenced modules and/or click Add missing items to add other items from this node to the diagram.

You can double-click on any type to open it in the editor. If the type is defined in a compiled assembly, it is opened according to your preferred way of navigating to compiled code.

You can get the detailed information on any specific type (as well as on any dependency between types). To get details of a type, hover the mouse over it, and as soon as the details pop-up appears, move the mouse pointer on it.

On the type details popup, you will see which types the given types uses, where the type is used, inherited types, types use in constructor parameters and more.
If the type has XML documentation, the summary is also displayed on the pop-up.

You can click on types to add them to the diagram. Types highlighted with green are already added to the diagram. If you click on such type, the diagram focus moves to it. The Go to declaration link in the top upper corner allows you to open the type in the editor.

Details of specific type on the dependency diagram

Studying dependencies between types

On the type dependency diagram, you can visualize several kinds of dependencies. To show or hide specific kinds of dependencies, use the corresponding items in the Filter Dependencies /help/img/dotnet/2016.3/ThemedIcon.Filter.Screen.[Gray].png selector:

  • Aggregation Dependencies - displays a kind of dependency when a type is a collection or container of other types,
    This kind of dependency is shown as a green dotted line. Name of the corresponding field is shown next to the line. You can hover the mouse over this line to see the field declaration and navigate to the corresponding place in the editor.
  • Usages Dependencies - displays a kind of dependency when variables, parameters or method returns of one type are used in another type.
    This kind of dependency is shown as a blue line whose thickness reflects a relative number of usages. You can hover the mouse over this line to see the list of usages:
    Usage dependency

    Clicking on specific usages will bring you to the corresponding place in the text editor, clicking on the Show all usages link opens all usages in the Find Results window.
  • Inheritance Dependencies - displays a kind of dependency when one type extends or implements another type. This kind of dependency is shown as a grey line. You can hover the mouse over this line to see the inheritance relation and navigate to the corresponding place in the editor.
    Transitive inheritance dependencies are shown using dashed lines. You can hover the mouse over such lines and use the popup to check the types though which the dependency goes and add these types to the diagram by clicking on them.
    Transitive dependency
  • Return Type Dependencies - displays a kind of dependency when one type has methods or properties that return another type. This kind of dependency is shown as a violet line. You can hover the mouse over this line to see the list of members and navigate to the corresponding places in the editor.
  • Constructor Injection - displays a kind of dependency when one type is exposed as a constructor parameter of another type. This kind of dependency is shown as a brown line. You can hover the mouse over this line to see the constructors and navigate to the corresponding places in the editor.

Invoking other ReSharper features on the diagram

Navigating from items on the diagram

To list all available navigation destinations of any item in the Navigate To menu, press Ctrl+Shift+G or right-click the item and choose Navigate To.

You can locate any item (file, folder, or project) in the Solution Explorer by pressing Shift+Alt+L when the item is selected.

You can also list related usages by clicking Show all used types in find results window or Show all usages in find results window in the details pop-up of a type or Show all usages in the pop-up of a dependency link.

Refactoring items on the diagram

From any item on the diagram, you can invoke all available refactorings. To do so, press Ctrl+Shift+R or right-click and choose Refactor This.

You can also perform the Move to Folder refactoring by dragging a type to the desired folder. This refactoring would move the file containing the type to the target folder, fix namespace references and change internal visibility to public if necessary.
Note that by default, this behavior is enabled. To disable it, click Allow 'Move to Folder' on drag-n-drop /help/img/dotnet/2016.3/ThemedIcon.RefactorThis.Screen.[Gray].png.

Note that after the drag-n-drop refactoring, the diagram is updated automatically, but other refactorings that you invoke from the Refactor This menu do not update the diagram; you will need to click Refresh Type Dependencies /help/img/dotnet/2016.3/ThemedIcon.Refresh.Screen.[Gray].png on the diagram's toolbar.

Exporting Diagram to image

At any point of exploring dependencies, you can export the current view to an image. To do so, click Export to PNG /help/img/dotnet/2016.3/ThemedIcon.Export.Screen.[Gray].png and specify where to save the image file.

This feature is supported in the following languages/technologies:

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

Last modified: 12 October 2017

See Also