The Basics - Generating the C# Code for the Logon Class
(Page 5 of 8 )
Now that you have modified the Logon class for C#, it’s time to see the code that VEA generates from the model. Exercise 1-8 shows how to generate the C# code.
EXERCISE 1-8
- Select the Logon class.
- Select UML -> Code -> Generate. This brings up the Generate dialog box.
- Make sure C# is selected in the Target language list.
- Select the Logon class in the Select classes for code generation tree view.
- Select the location you want the generated output placed in by typing the path in the Location text box or by browsing to the location after clicking the Browse button. Save the output with this name and path for easy access in later exercises and chapters: \EDWVSNETUMLMSF\ Chapter 01\C#\TopPackage\Logon.cs.
6. Click OK. You might be prompted to create a nonexistent folder.
If so, click Yes.
Let’s take a look at the generated C# code. Go to the output location you specified in the Generate dialog box and double-click the Logon.cs file. The code file is now opened in the VS .NET IDE, and it should look like the one shown in Figure 1-10.

Figure 1-10. The generated C#code for the Logon class
Figure 1-10 shows the generated output for the Logon class from the UML model as C# code.
Code Generation Summary As you’ve seen from the previous exercises, the code generated by VEA is nothing more than a skeleton of the class(es) you have in your UML model. However, you can add significantly more to your diagrams and have it reflected in the generated code. Specifically, we’re thinking about documentation here, in the form of comments in the code, initial attribute values, visibility, scope, multiplicity in the form of collections and arrays, and so on.
Modeling a Database The Logon class you created in the previous section needs to do some database lookup in order to validate the user that is trying to log on. Therefore, you need a database, which you’ll be modeling in this section. In standard UML, you normally model a database as a class diagram, giving it a Table stereotype. (We’ll talk more about stereotypes in later chapters.) VEA doesn’t support the generation of Data Definition Language (DDL) scripts from class diagrams, which means you can’t do it that way. However, VEA (and the standard versions of Visio) has a perhaps better way of dealing with databases: the database model diagram.
Creating the Database Model Diagram VEA offers database modelers several options, including entity-relationship (ER) and Object Role Modeling (ORM) diagrams. However, in this book, we’ll be using the database model diagram.
This article is excerpted from Enterprise Development with Visual Studio .NET, UML, and MSF by John Erik Hansen and Carsten Thomsen (Apress, 2004; ISBN 1590590422). Check it out at your favorite bookstore today. Buy this book now. |
Next: ER and ORM Diagrams >>
More .NET Articles
More By Apress Publishing