#766 – Adding an Interface to a Class Diagram

If you add a class to a class diagram and the class implements one or more interfaces, you’ll see the interfaces show up on the class with the standard interface designator (a short line with a circle at the end).

766-001

 

You can also add an element to the class diagram that represents the interface itself.  To do this, just right-click on an interface and select Show Interface.

766-002

 

Once you do this, the interface will be added to the diagram.  You can then expand the basic element to see the members of the interface.

766-003

#765 – Adding Base or Derived Classes to a Class Diagram

You can use the class diagram to follow the inheritance chain for any class currently in the diagram, moving up to the class’ base class or down to the classes that derive from the class.

For example, let’s say that you’ve dragged the ArgumentException class onto a class diagram, from the Class View.

Capture

 

You can add the base class of ArgumentException to the diagram by right-clicking on the class and selecting Show Base Class.

765-002

 

The base class will now be shown on the diagram.

765-003

 

You can also show all derived classes of a particular class by right-clicking on the class and selecting Show Derived Classes.

765-004

 

Using this technique, you can easily browse through the classes in the .NET Framework.

765-005

#764 – Expanding All Classes in a Class Diagram

By default, when you add types to a class diagram, they are displayed collapsed, showing only the name of the type and the category (e.g. class, interface).

764-001

You can expand individual types by clicking on the double downward facing arrow.  You’ll then see all the members of the type.

You can use the “+” key on the numeric keypad to expand the currently selected type.  You can also do the following, to quickly expand all types:

  • Select all typeson the diagram by pressing Ctrl+A
  • Expand all types by pressiong the “+” key on the numeric keypad
  • Right-click on the diagram and select Layout Diagram

Selecting Layout Diagram will reorganize all types so that they are layed out in a nice way.  The only problem is that types that are not connected to other types in the diagram will once again be collapsed.  You’ll need to expand and manually lay out these types.

764-002

#763 – Fixing a Class Diagram that Cannot Find Types

If you create a class diagram that contains types found in assemblies that your project references, and then you leave the class diagram open when you close Visual Studio, you may see some errors in the class diagram when you re-open the solution.  The types on the class diagram may all be drawn in red and report “Type cannot be found”.

763-001

 

You can fix this problem by just closing and re-opening the class diagram.  The diagram will re-discover the information for the types.

763-002

 

#762 – Creating a Class Diagram Containing Types in the .NET Framework

You typically create a class diagram in a project for the custom types that you’ve created in that project.  You can also include types on a class diagram that come from assemblies that your project references, including the .NET Framework itself.

To add elements to a class diagram representing types in the .NET Framework, do the following:

Add a new class diagram to the project.  (Right-click on project, select AddNew Item, then select Class Diagram).

762-001

 

Switch from Solution Explorer to Class View and expand Project References until you find a namespace or type that you want to look at.

762-002

 

Left-click and drag the selected namespace onto the class diagram.  All types from that namespace will show up on the class diagram (initially zoomed out).

762-003

You can zoom in and expand types to see more details.

762-004

 

#761 – Create or Modify Type Members Using the Class Details Window

You can use the Class Details window to easily create or modify a type’s members.

To open the Class Details window, start by opening a class diagram.  If the Class Details window does not appear, right click on one of the types in the class diagram and select Class Details.

761-001

Once the Class Details window opens, you’ll see a full list of the type’s members (e.g. methods, properties, fields and events).  The columns of the Class Details window shows some basic information about each member.  You can also expand methods to see parameters of the method.

761-002

To add new members, just start typing the name of the new member in the appropriate group.  For example, to add a new property, left-click on <add property> and start typing the name of the property.

761-003

You can also add members by clicking on the icon in the upper left corner of the window.

761-004

#760 – Adding New Class Members from a Class Diagram

In addition to adding new types from a class diagram within Visual Studio, you can also add members to existing types.

In the class diagram, you right-click the top area of the class and then click Add in the popup menu.  You’ll see a list of the different class members that you can add.

760-001

For example, we can add a RollOver method to the Dog class.  After selecting Method from the menu, a new method shows up in the list of methods for the class.

760-002

After you name the new method, different attributes of the method will show up in the Properties window on the right side of the Visual Studio workspace.  You can then make changes to the method by changing its properties.

760-003

You can of course go view or edit the new method in the code editor window.

760-004