How to: Generate Sequence Diagrams from Code

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

In Team System Architecture, you can generate a sequence diagram to help you visualize and understand how your code implements a particular method. A sequence diagram describes an interaction between objects as a series of lifelines and messages. Lifelines represent instances of objects, and messages represent method calls between those objects. You can generate sequence diagrams from Visual C# .NET or Visual Basic .NET code. A generated sequence diagram shows elements similar to those on a UML sequence diagram. For more information, see UML Sequence Diagrams: Introduction.

Note

Generated sequence diagrams do not show static method calls.

You can explore the diagram to help you identify changes that you might want to make to your code. You can edit the diagram to communicate those changes without affecting your code. For example, you can add new lifelines, messages, interaction uses, or other kinds of changes that you can make on a UML sequence diagram. For more information, see UML Sequence Diagrams: Guidelines.

Note

Any changes that you make to the diagram will not appear in your code. Any changes that you make to your code will not appear on the diagram. To show these changes, you must generate a new sequence diagram.

You can create and track tasks for work that you need to perform on the corresponding code by creating or linking work items to diagram elements. For more information, see How to: Link Work Items to Model Elements.

To generate a sequence diagram from code

  1. In Visual Studio, open the code file that contains the method definition.

  2. In the code editor window, right-click anywhere in the method definition, and then click Generate Sequence Diagram.

  3. In the Generate a Sequence Diagram dialog box, in the Maximum Call Depth box, specify the maximum level of method calls that you want to see.

    For example, if you want to see the first level of method calls only, specify a maximum call depth level of 1. The sequence diagram will show the next additional level of method calls as lost messages.

    Note

    Lost messages represent method calls to an unknown or unspecified instance.

  4. Under Generation Scope, the default scope shows calls only within the current solution. To show a different scope, choose one of the following:

    • To show calls only within the current project, click Current Project.

    • To show calls within and external to the solution, click Solution and External References.

  5. Under Namespace Filters, specify the namespaces that you want to omit as follows:

    • To omit the System namespace, make sure the System box is selected.

    • To include the System namespace, make sure the System box is cleared.

    • To filter other specific namespaces, type them in the Others box, using a semi-colon (;) to separate them.

  6. When you are finished, click OK.

    Visual Studio generates a sequence diagram and adds it to the corresponding project.

Exploring Your Code on Sequence Diagrams

To help you explore your code from the diagram, you can perform the following tasks:

  • Expand lost messages to show target lifelines.

    Lost messages represent method calls to an unknown or unspecified instance.

  • Generate sequence diagrams from messages to focus on specific lifelines.

  • Move messages to a new sequence diagram to create a reusable sequence.

  • Navigate from the diagram to the code to examine related code.

  • Collapse lifelines to hide details.

  • Improve the layout of the diagram.

  • Visualize relationships that lifelines and messages have with other parts of your code.

    You can find the corresponding classes and methods in Architecture Explorer and then generate directed graphs from them. For more information, see How to: Visualize Dependencies in Your Code.

To expand lost messages

  • Right-click a lost message, and then click Expand Outgoing.

    The sequence diagram uses the most recently used call depth to expand the lost message and show the target lifeline.

To generate sequence diagrams from messages

  1. Right-click a message, and then click Generate Sequence Diagram.

  2. In the Generate a Sequence Diagram dialog box, in the Maximum Call Depth box, specify the maximum level of method calls that you want to see.

    For example, if you want to see the first level of method calls only, specify a maximum call depth level of 1. The sequence diagram will show the next additional level of method calls as lost messages.

    Note

    Lost messages represent method calls to an unknown or unspecified instance.

  3. Under Generation Scope, the default scope shows calls only within the current solution. To show a different scope, choose one of the following:

    • To show calls only within the current project, click Current Project.

    • To show calls within and external to the solution, click Solution and External References.

  4. Under Namespace Filters, specify the namespaces that you want to omit, as follows:

    • To omit the System namespace, make sure the System box is selected.

    • To include the System namespace, make sure the System box is cleared.

    • To filter other specific namespaces, type them in the Others box, using a semi-colon (;) to separate them.

  5. When you are finished, click OK.

    Visual Studio generates a sequence diagram and adds it to the corresponding project.

To navigate from the diagram to the code

  • Right-click a lifeline or a message, and then click Show Code.

To collapse or expand lifelines

  • To collapse lifelines, select the lifelines, right-click your selection, and then click Collapse.

    Note

    You can rename the group; however, this name will be lost when you expand the group.

  • To expand collapsed lifelines, right-click the collapsed lifelines, and then click Expand.

To improve the layout

  • Right-click a blank area of the diagram, and then click Rearrange Layout.

    Note

    You can also undo this operation.

To find corresponding classes and methods in Architecture Explorer

  • Right-click a message or lifeline, and then click Show in Architecture Explorer.

See Also

Concepts

Understanding Your Current System