February 17th, 2008
Code Expansions and Surround with Technology Visual Studio 2005 (as well as Visual C# 2005 Express) also has the capability to insert complex blocks of C# code using menu selections, context-sensitive mouse clicks, and/or keyboard shortcuts. The number of available code expansions is impressive and can be broken down into two main groups: Snippets: These templates insert common code blocks at the location of the mouse cursor. Surround With: These templates wrap a block of selected statements within a relevant scope. To see this functionality firsthand, right-click a blank line within your Main() method and activate the Insert Snippet menu. Once you select a given item, you will find the related code is expanded automatically (press the Esc key to dismiss the pop-up menu). If you were to right-click and select the Surround With menu, you would likewise be presented with a list of options. Be sure to take time to explore these predefined code expansion templates, as they can radically speed up the development process. Note All code expansion templates are XML-based descriptions of the code to generate within the IDE. Using Visual Studio 2005 (as well as Visual C# 2005 Express), you can create your own custom code templates. Details of how to do so can be found in my article Investigating Code Snippet Technology at http://msdn.microsoft.com. The Visual Class Designer Visual Studio 2005 gives us the ability to design classes visually (but this capability is not included in Visual C# 2005 Express). The Class Designer utility allows you to view and modify the relationships of the types (classes, interfaces, structures, enumerations, and delegates) in your project. Using this tool, you are able to visually add (or remove) members to (or from) a type and have your modifications reflected in the corresponding C# file. As well, as you modify a given C# file, changes are reflected in the class diagram. To work with this aspect of Visual Studio 2005, the first step is to insert a new class diagram file. There are many ways to do so, one of which is to click the View Class Diagram button located on Solution Explorer s right side (see Figure 2-22). CHAPTER 2 BUILDING C# APPLICATIONS 57 Figure 2-22. Inserting a class diagram file Once you do, you will find class icons that represent the classes in your current project. If you click the arrow image, you can show or hide the type s members (see Figure 2-23).
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.
Posted in Coldfusion | No Comments »
February 16th, 2008
To illustrate refactoring in action, update your Main() method with the following code: static void Main(string[] args) { // Set up Console UI (CUI) Console.Title = “My Rocking App”; Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Blue; Console.WriteLine(”*************************************”); Console.WriteLine(”***** Welcome to My Rocking App *****”); Console.WriteLine(”*************************************”); Console.BackgroundColor = ConsoleColor.Black; // Wait for key press to close. Console.ReadLine(); } While there is nothing wrong with the preceding code as it now stands, imagine that you want to display this prompt at various places throughout your program. Rather than retyping the same exact console user interface logic, it would be ideal to have a helper function that could be called to do so. Given this, you will apply the Extract Method refactoring to your existing code. First, select each code statement (except the final call to Console.ReadLine()) within the editor. Now, right-click and select the Extract Method option from the Refactor context menu. Name your new method ConfigureCUI() in the resulting dialog box. When you have finished, you will find that your Main() method calls the newly generated ConfigureCUI() method, which now contains the previously selected code: class Program { static void Main(string[] args) { ConfigureCUI(); // Wait for key press to close. Console.ReadLine(); } private static void ConfigureCUI() { // Set up Console UI (CUI) Console.Title = “My Rocking App”; Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Blue; Console.WriteLine(”*************************************”); Console.WriteLine(”***** Welcome to My Rocking App *****”); Console.WriteLine(”*************************************”); Console.BackgroundColor = ConsoleColor.Black; } } Note If you are interested in more information on the refactoring process and a detailed walk-through of each refactoring supported by Visual Studio 2005, look up my article Refactoring C# Code Using Visual Studio 2005 online at http://msdn.microsoft.com. CHAPTER 2 56 BUILDING C# APPLICATIONS
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
Posted in Coldfusion | No Comments »
February 15th, 2008
CHAPTER 2 BUILDING C# APPLICATIONS 55 Integrated Support for Code Refactoring One major enhancement that ships with Visual Studio 2005 is intrinsic support to refactor existing code. Simply put, refactoring is a formal and mechanical process whereby you improve an existing code base. In the bad old days, refactoring typically involved a ton of manual labor. Luckily, Visual Studio 2005 does a great deal to automate the refactoring process. Using the Refactor menu, related keyboard shortcuts, smart tags, and/or context-sensitive mouse clicks, you can dramatically reshape your code with minimal fuss and bother. Table 2-4 defines some common refactorings recognized by Visual Studio 2005. Table 2-4. Visual Studio 2005 Refactorings Refactoring Technique Meaning in Life Extract Method Allows you to define a new method based on a selection of code statements Encapsulate Field Turns a public field into a private field encapsulated by a C# property Extract Interface Defines a new interface type based on a set of existing type members Reorder Parameters Provides a way to reorder member arguments Remove Parameters Removes a given argument from the current list of parameters (as you would expect) Rename Allows you to rename a code token (method name, field, local variable, and so on) throughout a project Promote Local Variable to Parameter Moves a local variable to the parameter set of the defining method Figure 2-21. The Visual Studio 2005 Object Browser utility
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
Posted in Coldfusion | No Comments »
February 14th, 2008
CHAPTER 2 54 BUILDING C# APPLICATIONS The Code Definition Window If you have a background in programming with .NET 1.1, you may be familiar with the Windows Forms Class Viewer utility, wincv.exe. This tool allowed you to type in the name of a .NET type and view its C# definition. While wincv.exe is deprecated with the release of .NET 2.0, an enhanced version of this tool has been integrated within Visual C# 2005 Express and Visual Studio 2005. You can activate the Code Definition window using the View menu. Simply place your mouse cursor over any type in your C# code files, and you will be presented with a snapshot of the type in question. For example, if you click the word string within your Main() method, you find the definition of the System.String class type (see Figure 2-20). The Object Browser Utility As you may recall from Chapter 1, Visual Studio 2005 also provides a utility to investigate the set of referenced assemblies within your current project. Activate the Object Browser using the View .Other Windows menu, and then select the assembly you wish to investigate (see Figure 2-21). Figure 2-19. The Class View utility Figure 2-20. The Code Definition window
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.
Posted in Coldfusion | No Comments »
February 13th, 2008
CHAPTER 2 BUILDING C# APPLICATIONS 53 Note Visual Studio 2005 now allows you to set references to executable assemblies (unlike Visual Studio .NET 2003, in which you were limited to *.dll code libraries). Finally, notice an icon named Properties within Solution Explorer. When you double-click this item, you are presented with an enhanced project configuration editor (see Figure 2-18). You will see various aspects of the Project Properties window as you progress through this text. However, if you take some time to poke around, you will see that you can establish various security settings, strongly name your assembly, insert string resources, and configure pre- and postbuild events. The Class View Utility The next tool to examine is the Class View utility, which you can load from the View menu. Like SharpDevelop, the purpose of this utility is to show all of the types in your current project from an object-oriented perspective. The top pane displays the set of namespaces and their types, while the bottom pane displays the currently selected type s members (see Figure 2-19). Figure 2-18. The Project Properties window
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.
Posted in Coldfusion | No Comments »
February 12th, 2008
CHAPTER 2 52 BUILDING C# APPLICATIONS Learning the Lay of the Land:Visual Studio 2005 Visual Studio 2005 ships with the expected GUI designers, database manipulation tools, object and project browsing utilities, and an integrated help system. Unlike the IDEs we have already examined, Visual Studio 2005 provides numerous additions. Here is a partial list: Visual XML editors/designers Support for mobile device development (such as Smartphones and Pocket PC devices) Support for Microsoft Office development The ability to track changes for a given source document and view revisions Integrated support for code refactoring An XML-based code expansion library Visual class design tools and object test utilities A code definition window (which replaces the functionality of the Windows Forms Class Viewer, wincv.exe, which shipped with .NET 1.1 and earlier) To be completely honest, Visual Studio 2005 provides so many features that it would take an entire book (a large book at that) to fully describe every aspect of the IDE. This is not that book. However, I do want to point out some of the major enhancements in the pages that follow. As you progress through the text, you ll learn more about the Visual Studio 2005 IDE where appropriate. The Solution Explorer Utility If you are following along, create a new C# console application (named Vs2005Example) using the File .New .Project menu item. The Solution Explorer utility (accessible from the View menu) allows you to view the set of all content files and referenced assemblies that comprise the current project (see Figure 2-17). Notice that the References folder of Solution Explorer displays a list of each assembly you have currently referenced (console projects reference System.dll, System.Data.dll, and System.Xml.dll by default). When you need to reference additional assemblies, right-click the References folder and select Add Reference. At this point, you can select your assembly from the resulting dialog box. Figure 2-17. Solution Explorer
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.
Posted in Coldfusion | No Comments »
February 11th, 2008
CHAPTER 2 BUILDING C# APPLICATIONS 51 Visual C# 2005 Express,Visual C++ 2005 Express, and Visual J# 2005 Express: Targeted IDEs for students and enthusiasts who wish to learn the fundamentals of computer science in their syntax of choice SQL Server 2005 Express: An entry-level database management system geared toward hobbyists, enthusiasts, and student developers Note At the time of this writing, the Express family products are available as public betas free of charge. By and large, Express products are slimmed-down versions of their Visual Studio 2005 counterparts and are primarily targeted at .NET hobbyists and students. Like SharpDevelop, Visual C# 2005 Express provides various browsing tools, aWindows Forms designer, the Add References dialog box, IntelliSense capabilities, and code expansion templates. As well, Visual C# 2005 Express offers a few (important) features currently not available in SharpDevelop, including An integrated graphical debugger Tools to simplify access to XML web services Because the look and feel of Visual C# 2005 Express is so similar to that of Visual Studio 2005 (and, to some degree, SharpDevelop) I do not provide a walk-through of this particular IDE here. If you do wish to learn more about the product, look up my article An Introduction to Programming Using Microsoft Visual C# 2005 Express Edition online at http://msdn.microsoft.com. The Big Kahuna: Building .NET Applications Using Visual Studio 2005 If you are a professional .NET software engineer, the chances are extremely good that your employer has purchased Microsoft s premier IDE, Visual Studio 2005, for your development endeavors (http://msdn.microsoft.com/vstudio). This tool is far and away the most feature-rich and enterpriseready IDE examined in this chapter. Of course, this power comes at a price, which will vary based on the version of Visual Studio 2005 you purchase. As you might suspect, each version supplies a unique set of features. My assumption during the remainder of this text is that you have chosen to make use of Visual Studio 2005 as your IDE of choice. Do understand that owning a copy of Visual Studio 2005 is not required for you to use this edition of the text. In the worst case, I may examine an option that is not provided by your IDE. However, rest assured that all of this book s sample code will compile just fine when processed by your tool of choice. Note Once you download the source code for this book from the Downloads area of the Apress website (http://www.apress.com), you may load the current example into Visual Studio 2005 by double-clicking the example s *.sln file. If you are not using Visual Studio 2005, you will need to manually configure your IDE to compile the provided *.cs files.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.
Posted in Coldfusion | No Comments »
February 11th, 2008
CHAPTER 2 50 BUILDING C# APPLICATIONS Using this same window, you can handle events for a given GUI item. To do so, click the lightning bolt icon at the top of the Properties window. Next, select the GUI item you wish to interact with from the drop-down list (your Button in this case). Finally, handle the Click event by typing in the name of the method to be called when the user clicks the button (see Figure 2-16). Once you press the Enter key, SharpDevelop responds by generating stub code for your new method. To complete the example, enter the following statement within the scope of your event handler: void ButtonClicked(object sender, System.EventArgs e) { // Update the Form’s caption with a custom message. this.Text = “Stop clicking my button!”; } At this point, you can run your program (using the Debug .Run menu item). Sure enough, when you click your Button, you should see the Form s caption update as expected. That should be enough information to get you up and running using the SharpDevelop IDE. I do hope you now have a good understanding of the basics, though obviously there is much more to this tool than presented here. Building .NET Applications Using Visual C# 2005 Express During the summer of 2004, Microsoft introduced a brand-new line of IDEs that fall under the designation of Express products (http://msdn.microsoft.com/express). To date, there are six members of the Express family: Visual Web Developer 2005 Express: A lightweight tool for building dynamic websites and XML web services using ASP.NET 2.0 Visual Basic 2005 Express: A streamlined programming tool ideal for novice programmers who want to learn how to build applications using the user-friendly syntax of Visual Basic .NET Figure 2-16. Handing events via the Properties window
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.
Posted in Coldfusion | No Comments »
February 10th, 2008
CHAPTER 2 BUILDING C# APPLICATIONS 49 The right side of the Assembly Scout utility allows you to view details of the item selected on the left pane. Not only can you view the basic details using the Info tab, but also you can also view the underlying CIL code of the item and save its definition to an XML file. Windows Forms Designers As you will learn later in this book, Windows Forms is a toolkit used to build desktop applications. To continue tinkering with SharpDevelop, click the Design tab located at the bottom of the MainForm.cs code window. Once you do, you will open the integrated Windows Forms designer. Using the Windows Forms section of your Tools window, you can create a GUI for the Form you are designing. To demonstrate this, place a single Button type on your main Form by selecting the Button icon and clicking the designer. To update the look and feel of any GUI item, you can make use of the Properties window (see Figure 2-15), which you activate from the View . Properties menu selection. Select the Button from the drop-down list and change various aspects of the Button type (e.g., BackColor and Text). Figure 2-14. Viewing referenced assemblies using the Assembly Scout Figure 2-15. The Properties window
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.
Posted in Coldfusion | No Comments »
February 9th, 2008
CHAPTER 2 48 BUILDING C# APPLICATIONS The Classes Scout provides a more object-oriented view of your combine in that it displays the namespaces, types, and members within each project (see Figure 2-13). If you double-click any item, SharpDevelop responds by opening the corresponding file and placing your mouse cursor at the item s definition. The Assembly Scout The Assembly Scout utility (accessible from the View menu) allows you to graphically browse the assemblies referenced within your project. This tool is split into two panes. On the left is a tree view control that allows you to drill into an assembly and view its namespaces and the contained types (see Figure 2-14). Figure 2-12. The SharpDevelop Add Reference dialog box Figure 2-13. The Classes Scout
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.
Posted in Coldfusion | No Comments »