#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).



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



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).


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



#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.


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.


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.


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


#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.


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.


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.


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


#759 – Creating a New Type from a Class Diagram

You can create new types by directly entering code in the editor window.  You can also add a new type from a class diagram.

To start with, either open an existing class diagram or create a new one.

To create a new type, right-click on an empty area in the class diagram and select Add and then Class.  Note that you can also create other types (e.g. Enum, Interface, or Struct).



The New Class dialog will appear and you can enter the name of the new class and select an access modifier.  Note that the filename will be based on the class name by default.



After you click OK, the new type will show up in the class diagram.



You can now open your new type in the code editor window, to see the code that was generated for you.



#758 – Cleaning Up using Directives in a File

You use using directives at the top of a file to bring various namespaces into scope, so that you don’t need to fully qualify named members within those namespaces.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

Extra using directives don’t hurt anything–the list of directives is just a list of possible namespaces to consult when resolving a name.  Your code may not actually reference members in all of the listed namespaces.

For cosmetic purposes, however, there is an easy command in Visual Studio that you can use to clean up using directives for namespaces that you don’t use.

To remove unused namespaces, you can right-click in the source code editor and select Organize Usings and then Remove Unused Usings.  After you do this, you’ll be left only with namespaces that contain members that your code contains.




#756 – Viewing a Class Diagram in Visual Studio 2012

You can create and view a class diagram from within Visual Studio that shows all of the types in your project and their relationships.  This is helpful in understanding how your project is structured.

To create a class diagram that allows viewing all types in your project, do the following.

In Solution Explorer, right-click the project and select View Class Diagram.



A diagram will appear that shows all of the types in your project.  In this example, the diagram also shows that Terrier is a subclass of Dog and that the Dog class implements the IBark and IFetch interfaces.

You can also click on the double down arrow icon to expand any of the types.  (You may have to move them around to make things look pretty again).



You can also navigate to the code for any member shown in the diagram, by right-clicking on the member and selecting View Code.


#755 – Viewing Class Members Directly in the Solution Explorer

In Visual Studio 2012, you most often use Solution Explorer to see the files within your solutions and projects.  Double-clicking on a file opens it in the code editor window.



However, you can also see information about the types in your code, using the Solution Explorer.  By using the little arrows to the left of each file, you can open up the file to see all of the types defined in the file.  You can then drill down into each type to see all of its members.  Double-clicking on a specific member will open the code editor window and navigate to the declaration of that member.


#747 – Turning Off All Caps Menus in Visual Studio 2012

One of the changes in Visual Studio 2012 was to render the main menus in all caps.  This was done to better match the new Metro (Windows Store) style of user interface, used across other Microsoft products.  (E.g. Office 2013 or the Bing web site).


However, many people have argued that using all caps make the user interface less readable and constitutes bad typography.

If you prefer using upper and lowercase in the main menu, you can turn off the all caps by adding a value in the registry.

In the key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General, create a DWORD value named SuppressUppercaseConversion and set its value to 1.

You’ll now get upper and lowercase in the menus.


#746 – Get a Free Copy of Visual Studio 2012

You can start using C# to develop applications by using one of the Visual Studio 2012 Express editions.  Each of the editions listed below is free and allows you to create applications for the listed platform.

  • Visual Studio Express 2012 for Web
  • Visual Studio Express 2012 for Windows 8  (Windows Store apps)
  • Visual Studio Express 2012 for Windows Desktop
  • Visual Studio Express 2012 for Windows Phone

Additionally, you can get a free copy of Visual Studio Team Foundation Server Express 2012, which allows up to five developers to do source code control, work item tracking, and build automation.

#691 – Use the this Keyword to Trigger Intellisense

Another use of the this keyword, which refers to the current instance of a class, is to trigger Intellisense in Visual Studio so that you can  see a list of members in the class.

For example, let’s say that you’re writing some code for the Bark method in a Dog class.  You want to call another method in the Dog class, but you can’t remember its name.  You can just type this and a period (.).  After typing the period, an Intellisense window will pop up to show you the members in the Dog class.

You can then select the method that you want to call and Intellisense will remind you of what parameters are required.