Defining Methods, Properties, Fields, and Events

The most exciting part of the class designer is that it allows you to do more than define classes and relationships. You can actually stub out code and do refactoring. (See Chapter 9, “Refactoring Code,” for details.)

There are two ways to add code to your classes, structs, interfaces, and the like. The first is to type directly into the designer. For example, if you are in the Properties section of a class, you can right-click and choose to add a new property. This places the property in your class and allows you to edit it in the diagram. This method works for other class members as well. It does have a couple of drawbacks, however. You can’t, for instance, define a full method signature or indicate access levels. For that, you need the Class Details window.

The Class Details window allows you to fully define methods, fields, properties, and events for a class. It also works with other constructs such as interfaces, delegates, and enums. To use this window, right-click a class and choose Class Details from the context menu. Selecting this menu item brings up the Class Details editor for the selected class. Figure 6.58 shows the Class Details window in action.

Image

FIGURE 6.58 Creating a method in the Class Details window.

Notice that when working in the Class Details window, you still get IntelliSense. In this example, the Cancel method is being added to the Order class. You can indicate a return type for the method with the Type column. You can define the access modifier with the Modifier column. You can also set the parameters of the method. In this case, the method takes the string parameter ReasonCode.

Finally, there are Summary and Hide columns. The Hide column indicates whether you want to show an item on the diagram. This capability allows you to hide various members when printing or exporting as an image. The Summary column allows you to add your XML documentation to the class. Clicking the ellipsis button (not shown) in this field brings up the Description dialog box. Here, you can enter your XML summary information for the given member. Figure 6.59 shows an example for the Cancel method.

Image

FIGURE 6.59 Creating code comments for a method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset