<<

A P E N I X A

■ ■ ■

Programming with

Since the release of the .NET platform (circa 2001), the base class libraries have included a particular API named Windows Forms, represented primarily by the System.Windows.Forms.dll . The Windows Forms toolkit provides the types necessary to build desktop graphical user interfaces (GUIs), create custom controls, manage resources (e.g., string tables and icons), and perform other desktop- centric programming tasks. In addition, a separate API named GDI+ (represented by the System.Drawing.dll assembly) provides additional types that allow to generate 2D graphics, interact with networked printers, and manipulate image data. The Windows Forms (and GDI+) remain alive and well within the .NET 4.0 platform, and they will exist within the base class for quite some time (arguably forever). However, has shipped a brand new GUI toolkit called Windows Presentation Foundation (WPF) since the release of .NET 3.0. As you saw in Chapters 27-31, WPF provides a massive amount of horsepower that you can use to build bleeding-edge user interfaces, and it has become the preferred desktop API for today’s .NET graphical user interfaces. The point of this appendix, however, is to provide a tour of the traditional Windows Forms API. One reason it is helpful to the original programming model: you can many existing Windows Forms applications out there that will need to be maintained for some time to come. Also, many desktop GUIs simply might not require the horsepower offered by WPF. When you need to create more traditional business UIs that do not require an assortment of bells and whistles, the Windows Forms API can often fit the bill. In this appendix, you will learn the Windows Forms programming model, work with the integrated designers of Visual Studio 2010, experiment with numerous Windows Forms controls, and receive an overview of graphics programming using GDI+. You will also pull this information together in a cohesive whole by wrapping things up in a (semi-capable) painting application.

■ Note Here’s one proof that Windows Forms is not disappearing anytime soon: .NET 4.0 ships with a brand new Windows Forms assembly, System.Windows.Forms.DataVisualization.dll. You can use this library to incorporate charting functionality into your programs, complete with annotations; 3D rendering; and hit-testing support. This appendix will not cover this new .NET 4.0 Windows Forms API; however, you can look up the System.Windows.Forms.DataVisualization.Charting namespace if you want more information.

1511

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

The Windows Forms Namespaces The Windows Forms API consists of hundreds of types (e.g., classes, interfaces, structures, enums, and delegates), most of which are organized within various namespaces of the System.Windows.Forms.dll assembly. Figure A-1 shows these namespaces displayed in the Visual Studio 2010 object browser.

Figure A-1. The namespaces of System.Windows.Forms.dll

Far and away the most important Windows Forms namespace is System.Windows.Forms. At a high level, you can group the types within this namespace into the following broad categories: • Core infrastructure: These are types that represent the core operations of a Windows Forms program (e.g., Form and Application) and various types to facilitate interoperability with legacy ActiveX controls, as well as interoperability with new WPF custom controls. • Controls: These are types used to create graphical UIs (e.g., , MenuStrip, ProgressBar, and DataGridView), all of which derive from the Control base class. Controls are configurable at design time and are visible (by default) at runtime. • Components: These are types that do not derive from the Control base class, but still may provide visual features to a Windows Forms program (e.g., and ErrorProvider). Many components (e.g., the Timer and System.ComponentModel.BackgroundWorker) are not visible at runtime, but can be configured visually at design time. • Common boxes: Windows Forms provides several canned dialog boxes for common operations (e.g., OpenFileDialog, PrintDialog, and ColorDialog). As you would hope, you can certainly build your own custom dialog boxes if the standard dialog boxes do not suit your needs. Given that the total number of types within System.Windows.Forms is well over 100 strong, it would be redundant (not to mention a terrible waste of paper) to list every member of the Windows Forms

1512

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

family. As you work through this appendix, however, you will gain a firm foundation that you can build on. In any case, be sure to check out the .NET Framework 4.0 SDK documentation for additional details.

Building a Simple Windows Forms Application As you might expect, modern .NET IDEs (e.g., Visual Studio 2010, # 2010 Express, and SharpDevelop) provide numerous designers, visual editors, and integrated code-generation tools (wizards) to facilitate the construction of Windows Forms applications. These tools are extremely useful, but they can also hinder the of learning Windows Forms, because these same tools tend to generate a good deal of boilerplate code that can obscure the core . Given this, you will create your first Windows Forms example using a Console Application project as a starting point. Begin by creating a Console Application named SimpleWinFormsApp. Next, use the Project ➤ Add Reference option to set a reference to the System.Windows.Forms.dll and System.Drawing.dll assemblies through the .NET of the resulting . Next, update your Program.cs file with the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text;

// The minimum required windows forms namespaces. using System.Windows.Forms; namespace SimpleWinFormsApp { // This is the application object. class Program { static void Main(string[] args) { Application.Run(new MainWindow()); } }

// This is the main . class MainWindow : Form {} }

■ Note When Visual Studio 2010 finds a class that extends System.Windows.Forms.Form, it attempts to open the related GUI designer (provided this class is the first class in the C# code file). Double-clicking the Program.cs file from the Solution Explorer opens the designer, but don’t do that yet! You will work with the Windows Forms designer in the next example; for now, be sure you right-click on the C# file containing your code within the Solution Explorer and select the View Code option.

1513

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

This code represents the absolute simplest Windows Forms application you can build. At a bare minimum, you need a class that extends the Form base class and a Main() method to call the static Application.Run() method (you can find more details on Form and Application later in this chapter). Running your application now reveals that you have a resizable, minimizable, maximizable, and closable topmost window (see Figure A-2).

Figure A-2. A simple Windows Forms application

■ Note When you run this program, you will notice a command prompt looming in the background of your topmost window. This is because, when you create a Console Application, the /target flag sent to the C# defaults to /target:exe. You can change this to /target:winexe (preventing the display of the command prompt) by double-clicking the Properties in the Solution Explorer and changing the Output Type setting to Windows Application using the Application tab.

Granted, the current application is not especially exciting, but it does illustrate how simple a Windows Forms application can be. To spruce things up a bit, you can add a custom constructor to your MainWindow class, which allows the caller to set various properties on the window to be displayed:

// This is the main window. class MainWindow : Form { public MainWindow() {} public MainWindow(string title, int height, int width) { // Set various properties from the parent classes. Text = title; Width = width; Height = height;

1514

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

// Inherited method to center the form on the screen. CenterToScreen(); } }

You can now update the call to Application.Run(), as follows: static void Main(string[] args) { Application.Run(new MainWindow("My Window", 200, 300)); }

This is a step in the right direction, but any window worth its salt requires various user interface elements (e.g., menu systems, status bars, and buttons) to allow for input. To understand how a Form- derived type can contain such elements, you must understand the role of the Controls and the underlying controls collection.

Populating the Controls Collection The System.Windows.Forms.Control base class (which is the inheritance chain of the Form type) defines a property named Controls. This property wraps a custom collection nested in the Control class named ControlsCollection. This collection (as the name suggests) references each UI element maintained by the derived type. Like other containers, this type supports several methods for inserting, removing, and finding a given UI widget (see Table A-1).

Table A-1. ControlCollection Members

Member Meaning in Life

Add() You use these members to insert a new Control-derived type (or array of AddRange() types) in the collection.

Clear() This member removes all entries in the collection.

Count This member returns the number of items in the collection.

Remove() You use these members to remove a control from the collection. RemoveAt()

When you wish to populate the UI of a Form-derived type, you typically follow a predictable series of steps: • Define a member variable of a given UI element within the Form-derived class. • Configure the of the UI element. • Add the UI element to the form’s ControlsCollection container using a call to Controls.Add().

1515

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Assume you wish to update your MainWindow class to support a File ➤ Exit menu system. Here are the relevant updates, with code analysis to follow:

class MainWindow : Form { // Members for a simple menu system. private MenuStrip mnuMainMenu = new MenuStrip(); private ToolStripMenuItem mnuFile = new ToolStripMenuItem(); private ToolStripMenuItem mnuFileExit = new ToolStripMenuItem();

public MainWindow(string title, int height, int width) { ... // Method to create the menu system. BuildMenuSystem(); }

private void BuildMenuSystem() { // Add the item to the main menu. mnuFile.Text = "&File"; mnuMainMenu.Items.Add(mnuFile);

// Now add the Exit menu to the File menu. mnuFileExit.Text = "E&xit"; mnuFile.DropDownItems.Add(mnuFileExit); mnuFileExit.Click += (o, s) => Application.Exit();

// Finally, set the menu for this Form. Controls.Add(this.mnuMainMenu); MainMenuStrip = this.mnuMainMenu; } }

Notice that the MainWindow type now maintains three new member variables. The MenuStrip type represents the entirety of the menu system, while a given ToolStripMenuItem represents any topmost menu item (e.g., File) or submenu item (e.g., Exit) supported by the host. You configure the menu system within the BuildMenuSystem() helper function. Notice that the text of each ToolStripMenuItem is controlled through the Text property; each menu item has been assigned a string literal that contains an embedded symbol. As you might already know, this syntax sets the Alt key shortcut. Thus, selecting Alt+F activates the File menu, while selecting Alt+X activates the Exit menu. Also notice that the File ToolStripMenuItem object (mnuFile) adds subitems using the DropDownItems property. The MenuStrip object itself adds a topmost menu item using the Items property. Once you establish the menu system, you can add it to the controls collection (through the Controls property). Next, you assign your MenuStrip object to the form’s MainMenuStrip property. This step might seem redundant, but having a specific property such as MainMenuStrip makes it possible to dynamically establish which menu system to show a user. You might change the menu displayed based on user preferences or security settings. The only other point of interest is the fact that you handle the Click event of the File ➤ Exit menu; this helps you capture when the user selects this submenu. The Click event works in conjunction with a standard delegate type named System.EventHandler. This event can only call methods that take a

1516

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

System.Object as the first parameter and a System.EventArgs as the second. Here, you use a lambda expression to terminate the entire application with the static Application.Exit() method. Once you recompile and execute this application, you will find your simple window sports a custom menu system (see Figure A-3).

Figure A-3. A simple window, with a simple menu system

The Role of System.EventArgs and System.EventHandler System.EventHandler is one of many delegate types used within the Windows Forms (and ASP.NET) APIs during the event-handling process. As you have seen, this delegate can only point to methods where the first argument is of .Object, which is a reference to the object that sent the event. For example, assume you want to update the implementation of the lambda expression, as follows: mnuFileExit.Click += (o, s) => { MessageBox.Show(string.Format("{0} sent this event", o.ToString())); Application.Exit(); };

You can verify that the mnuFileExit type sent the event because the string is displayed within the message box:

"E&xit sent this event"

You might be wondering what purpose the second argument, System.EventArgs, serves. In reality, the System.EventArgs type brings little to the table because it simply extends Object and provides practically nothing by way of addition functionality: public class EventArgs { public static readonly EventArgs Empty; static EventArgs(); public EventArgs(); }

However, this type is useful in the overall scheme of .NET event handling because it is the parent to many (useful) derived types. For example, the MouseEventArgs type extends EventArgs to provide details regarding the current state of the mouse. KeyEventArgs also extends EventArgs to provide details of the

1517

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

state of the keyboard (such as which key was pressed); PaintEventArgs extends EventArgs to yield graphically relevant data; and so forth. You can also see numerous EventArgs descendents (and the delegates that use of them) not only when working with Windows Forms, but when working with the WPF and ASP.NET APIs, as well. While you could continue to build more functionality into your MainWindow (e.g., status bars and dialog boxes) using a simple , you would eventually end up with hand cramps because you have to author all the grungy control configuration logic manually. Thankfully, Visual Studio 2010 provides numerous integrated designers that take care of these details on your behalf. As you use these tools during the remainder of this chapter, always remember that these tools authoring everyday C# code; there is nothing magical about them whatsoever.

You can find the SimpleWinFormsApp project under the Appendix A subdirectory.

The Visual Studio Windows Forms Project Template When you wish to leverage the Windows Forms designer tools of Visual Studio 2010, your typically begin by selecting the Windows Forms Application project template using the File ➤ New Project menu option. To get comfortable with the core Windows Forms designer tools, create a new application named SimpleVSWinFormsApp (see Figure A-4).

Figure A-4. The Visual Studio Windows Forms Project Template

1518

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

The Visual Designer Before you begin to build more interesting Windows applications, you will re-create the previous example leveraging the designer tools. Once you create a new Windows Forms project, you will notice that Visual Studio 2010 presents a designer surface to which you can drag-and-drop any number of controls. You can use this same designer to configure the initial size of the window simply by resizing the form itself using the supplied grab handles (see Figure A-5).

Figure A-5. The visual forms designer

When you wish to configure the look-and-feel of your window (as well as any control placed on a form designer), you do so using the Properties window. Similar to a Windows Presentation Foundation project, this window can be used to assign values to properties, as well as to establish event handlers for the currently selected item on the designer (you select a configuration using the drop-down mounted on the top of the Properties window). Currently, your form is devoid of content, so you see only a listing for the initial Form, which has been given a default name of Form1, as shown in the read-only Name property of Figure A-6.

Figure A-6. The Properties window for setting properties and handling events

1519

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

■ Note You can configure the Properties window to display its content by category or alphabetically using the first two buttons mounted beneath the drop-down list box. I’d suggest that you sort the items alphabetically to find a given property or event quickly.

The next designer element to be aware of is the Solution Explorer window. All Visual Studio 2010 projects support this window, but it is especially helpful when building Windows Forms applications to be able to (1) change the name of the file and related class for any window quickly, and (2) view the file that contains the designer-maintained code (you’ll learn more information on this tidbit in just a moment). For now, right-click the Form1.cs icon and select the Rename option. Name this initial window to something more fitting: MainWindow.cs. The IDE will ask you if you wish to change the name of your initial class; it’s fine to do this.

Dissecting the Initial Form Before you build your menu system, you need to examine exactly what Visual Studio 2010 has created by default. Right-click the MainWindow.cs icon from the Solution Explorer window and select View Code. Notice that the form has been defined as a partial type, which allows a single type to be defined within multiple code files (see Chapter 5 for more information about this). Also, note that the form’s constructor makes a call to a method named InitializeComponent() and your type is-a Form:

namespace SimpleVSWinFormsApp { public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); } } }

As you might be expecting, InitializeComponent() is defined in a separate file that completes the partial class definition. As a naming convention, this file always ends in .Designer.cs, preceded by the name of the related C# file containing the Form-derived type. Using the Solution Explorer window, open your MainWindow.Designer.cs file. Now, ponder the following code (this snippet strips out the code comments for simplicity; your code might differ slightly, based on the configurations you did in the Properties window):

partial class MainWindow { private System.ComponentModel.IContainer components = null;

protected override void Dispose(bool disposing) { if (disposing && (components != null)) {

1520

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

components.Dispose(); } base.Dispose(disposing); }

private void InitializeComponent() { this.SuspendLayout(); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(422, 114); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } }

The IContainer member variable and Dispose() methods are little more than infrastructure used by the Visual Studio designer tools. However, notice that the InitializeComponent() is present and accounted for. Not only is this method invoked by a form’s constructor at runtime, Visual Studio makes use of this same method at design time to render correctly the UI seen on the Forms designer. To see this in action, change the value assigned to the Text property of the window to "My Main Window". Once you activate the designer, the form’s caption will update accordingly. When you use the visual design tools (e.g., the Properties window or the form designer), the IDE updates InitializeComponent() automatically. To illustrate this aspect of the Windows Forms designer tools, ensure that the Forms designer is the active window within the IDE and find the Opacity property listed in the Properties window. Change this value to 0.8 (80%); this gives your window a slightly transparent look-and-feel the next time you compile and run your program. Once you make this change, reexamine the implementation of InitializeComponent(): private void InitializeComponent() { ... this.Opacity = 0.8; }

For all practical purposes, you should ignore the *.Designer.cs files and allow the IDE to maintain them on your behalf when you build a Windows Forms application using Visual Studio. If you were to author syntactically (or logically) incorrect code within InitializeComponent(), you might break the designer. Also, Visual Studio often reformats this method at design time. Thus, if you were to add custom code to InitializeComponent(), the IDE might delete it! In any case, remember that each window of a Windows Forms application is composed using partial classes.

Dissecting the Program Class Beyond providing implementation code for an initial Form-derived type, the Windows Application project types also provide a static class (named Program) that defines your program’s entry point, Main(): static class Program {

1521

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainWindow()); } }

The Main() method invokes Application.Run() and a few other calls on the Application type to establish some rendering options. Last but not least, note that the Main() method has been adorned with the [STAThread] attribute. This informs the runtime that if this happens to create any classic COM objects (including legacy ActiveX UI controls) during its lifetime, the runtime must place these objects in a COM-maintained area termed the single-threaded apartment. In a nutshell, this ensures that the COM objects are thread-safe, even if the author of a given COM object did not explicitly include code to ensure this is the case.

Visually Building a Menu System To wrap up this look at the Windows Forms visual designer tools and move on to some more illustrative examples, activate the Forms designer window, locate the Toolbox window of Visual Studio 2010, and find the MenuStrip control within the Menus & node (see Figure A-7).

Figure A-7. Windows Forms controls you can add to your designer surface

Drag a MenuStrip control onto the top of your Forms designer. Notice that Visual Studio responds by activating the menu editor. If you look closely at this editor, you will notice a small triangle on the top- right of the control. Clicking this icon opens a context-sensitive inline editor that allows you to make numerous property settings at once (be aware that many Windows Forms controls have similar inline editors). For example, click the Insert Standard Items option, as shown in Figure A-8.

1522

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-8. The inline menu editor

In this example, Visual Studio was kind enough to establish an entire menu system on your behalf. Now open your designer-maintained file (MainWindow.Designer.cs) and note the numerous lines of code added to InitializeComponent(), as well as several new member variables that represent your menu system (designer tools are good things!). Finally, flip back to the designer and undo the previous operation by clicking the Ctrl+Z keyboard combination. This brings you back to the initial menu editor and removes the generated code. Using the menu designer, type in a topmost File menu item, followed by an Exit submenu (see Figure A-9).

Figure A-9. Manually building our menu system

If you take a look at InitializeComponent(), you will find the same sort of code you authored by hand in the first example of this chapter. To complete this exercise, flip back to the Forms designer and click the lightning bolt button mounted on the Properties window. This shows you all of the events you can handle for the selected control. Make sure you select the Exit menu (named exitToolStripMenuItem by default), then locate the Click event (see Figure A-10).

1523

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-10. Establishing Events with the IDE

At this point, you can enter the name of the method to be called when the item is clicked; or, if you feel lazy at this point, you can double-click the event listed in the Properties window. This lets the IDE pick the name of the event handler on your behalf (which follows the pattern, NameOfControl_NameOfEvent()).In either case, the IDE will create stub code, and you can fill in the implementation details:

public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); CenterToScreen(); } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } }

If you so desire, you can take a quick peek at InitializeComponent(), where the necessary event riggings have also been accounted for:

this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);

At this point, you probably feel more comfortable moving around the IDE when building Windows Forms applications. While there are obviously many additional shortcuts, editors, and integrated code wizards, this information is more than enough for you to press onward.

1524

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

The Anatomy of a Form So far you have examined how to build simple Windows Forms applications with (and without) the aid of Visual Studio; now it’s time to examine the Form type in greater detail. In the world of Windows Forms, the Form type represents any window in the application, including the topmost main windows, child windows of a multiple document interface (MDI) application, as well as modal and modeless dialog boxes. As Figure A-11 shows, the Form type gathers a good deal of functionality from its parent classes and the numerous interfaces it implements.

Figure A-11. The inheritance chain of System.Windows.Forms.Form

Table A-2 offers a high-level look at each parent class in the Form’s inheritance chain.

Table A-2. Base Classes in the Form Inheritance Chain

Parent Class Meaning in Life

System.Object Like any class in .NET, a Form is-a object.

System.MarshalByRefObject Types deriving from this class are accessed remotely through a reference to (not a local copy of) the remote type.

System.ComponentModel. This class provides a default implementation of the IComponent Component interface. In the .NET universe, a component is a type that supports design-time editing, but it is not necessarily visible at runtime.

1525

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-2. Base Classes in the Form Inheritance Chain (continued)

Parent Class Meaning in Life

System.Windows.Forms.Control This class defines common UI members for all Windows Forms UI controls, including the Form type itself.

System.Windows.Forms. This class defines support for horizontal and vertical , as ScrollableControl well as members, which allow you to manage the viewport shown within the scrollable region.

System.Windows.Forms. This class provides focus-management functionality for controls ContainerControl that can function as a container for other controls.

System.Windows.Forms.Form This class represents any custom form, MDI child, or dialog box.

Although the complete derivation of a Form type involves numerous base classes and interfaces, you should keep in mind that you are not required to learn the role of each and every member of each and every parent class or implemented interface to be a proficient Windows Forms developer. In fact, you can easily set the majority of the members (specifically, properties and events) you use on a daily basis using the Visual Studio 2010 Properties window. That said, it is important that you understand the functionality provided by the Control and Form parent classes.

The Functionality of the Control Class The System.Windows.Forms.Control class establishes the common behaviors required by any GUI type. The core members of Control allow you to configure the size and position of a control, capture keyboard and mouse input, get or set the focus/visibility of a member, and so forth. Table A-3 defines some properties of interest, which are grouped by related functionality.

Table A-3. Core Properties of the Control Type

Property Meaning in Life

BackColor These properties define the core UI of the control (e.g., colors, font for text, ForeColor and the mouse cursor to display when the mouse is over the widget). BackgroundImage Font Cursor

Anchor These properties control how the control should be positioned within the Dock container. AutoSize

1526

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-3. Core Properties of the Control Type (continued)

Property Meaning in Life

Top These properties specify the current dimensions of the control. Left Bottom Right Bounds ClientRectangle Height Width

Enabled These properties encapsulate a Boolean that specifies the state of the Focused current control. Visible

ModifierKeys This static property checks the current state of the modifier keys (e.g., Shift, Ctrl, and Alt) and returns the state in a Keys type.

MouseButtons This static property checks the current state of the mouse buttons (left, right, and middle mouse buttons) and returns this state in a MouseButtons type.

TabIndex You use these properties to configure the tab order of the control. TabStop

Opacity This property determines the opacity of the control (0.0 is completely transparent; 1.0 is completely opaque).

Text This property indicates the string data associated with this control.

Controls This property allows you to access a strongly typed collection (e.g., ControlsCollection) that contains any child controls within the current control.

As you might guess, the Control class also defines a number of events that allow you to intercept mouse, keyboard, painting, and drag-and-drop activities, among other things. Table A-4 lists some events of interest, grouping them by related functionality.

1527

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-4. Events of the Control Type

Event Meaning in Life

Click These events that let you interact with the mouse. DoubleClick MouseEnter MouseLeave MouseDown MouseUp MouseMove MouseHover MouseWheel

KeyPress These events let you interact with the keyboard. KeyUp KeyDown

DragDrop You use these events to monitor drag-and-drop activity. DragEnter DragLeave DragOver

Paint This event lets you to interact with the graphical rendering services of GDI+.

Finally, the Control base class also defines a several methods that allow you to interact with any Control-derived type. As you examine the methods of the Control type, notice that a many of them have an On prefix, followed by the name of a specific event (e.g., OnMouseMove, OnKeyUp, and OnPaint). Each of these On-prefixed virtual methods is the default event handler for its respective event. If you override any of these virtual members, you gain the ability to perform any necessary pre- or post-processing of the event before (or after) invoking the parent’s default implementation:

public partial class MainWindow : Form { protected override void OnMouseDown(MouseEventArgs e) { // Add custom code for MouseDown event here.

// Call parent implementation when finished. base.OnMouseDown(e); } }

This can be helpful in some circumstances (especially if you want to build a custom control that derives from a standard control), but you will often handle events using the standard C# event syntax (in fact, this is the default behavior of the Visual Studio designers). When you handle events in this manner, the framework calls your custom event handler once the parent’s implementation has completed. For example, this code lets you manually handle the MouseDown event:

1528

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

public partial class MainWindow : Form { public MainWindow() { ... MouseDown += new MouseEventHandler(MainWindow_MouseDown); }

private void MainWindow_MouseDown(object sender, MouseEventArgs e) { // Add code for MouseDown event. } }

You should also be aware of a few other methods, in addition to the just described OnXXX() methods: • Hide(): Hides the control and sets the Visible property to false. • Show(): Shows the control and sets the Visible property to true. • Invalidate(): Forces the control to redraw itself by sending a Paint event (you learn more about graphical rendering using GDI+ later in this chapter).

The Functionality of the Form Class The Form class is typically (but not necessarily) the direct base class for your custom Form types. In addition to the large set of members inherited from the Control, ScrollableControl, and ContainerControl classes, the Form type adds additional functionality in particular to main windows, MDI child windows, and dialog boxes. Let’s start with the core properties in Table A-5.

Table A-5. Properties of the Form Type

Property Meaning in Life

AcceptButton Gets or sets the button on the form that is clicked when the user presses the Enter key.

ActiveMdiChild Used within the context of an MDI application. IsMdiChild IsMdiContainer

CancelButton Gets or sets the button control that will be clicked when the user presses the Esc key.

ControlBox Gets or sets a value that indicates whether the form has a control box (e.g., the minimize, maximize, and close icons in the upper right of a window).

FormBorderStyle Gets or sets the border style of the form. You use this in conjunction with the FormBorderStyle enumeration.

1529

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-5. Properties of the Form Type (continued)

Property Meaning in Life

Menu Gets or sets the menu to dock on the form.

MaximizeBox Used to determine whether this form will enable the maximize and MinimizeBox minimize boxes.

ShowInTaskbar Determines whether this form will be seen on the Windows .

StartPosition Gets or sets the starting position of the form at runtime, as specified by the FormStartPosition enumeration.

WindowState Configures how the form is to be displayed on startup. You use this in conjunction with the FormWindowState enumeration.

In addition to numerous On-prefixed default event handlers, Table A-6 provides a list of some core methods defined by the Form type.

Table A-6. Key Methods of the Form Type

Method Meaning in Life

Activate() Activates a given form and gives it focus.

Close() Closes the current form.

CenterToScreen() Places the form in the center of the screen

LayoutMdi() Arranges each child form (as specified by the MdiLayout enumeration) within the parent form.

Show() Displays a form as a modeless window.

ShowDialog() Displays a form as a modal dialog box.

Finally, the Form class defines a number of events, many of which fire during the form’s lifetime (see Table A-7).

1530

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-7. Select Events of the Form Type

Event Meaning in Life

Activated This event occurs whenever the form is activated, which means that the form has been given the current focus on the desktop.

FormClosed You use these events to determine when the form is about to close or has closed. FormClosing

Deactivate This event occurs whenever the form is deactivated, which means the form has lost the current focus on the desktop.

Load This event occurs after the form has been allocated into memory, but is not yet visible on the screen.

MdiChildActive This event is sent when a child window is activated.

The Life Cycle of a Form Type If you have programmed user interfaces using GUI toolkits such as , Mac OS X Cocoa, or WPF, you know that window types have many events that fire during their lifetime. The same holds true for Windows Forms. As you have seen, the life of a form begins when the class constructor is called prior to being passed into the Application.Run() method. Once the object has been allocated on the managed heap, the framework fires the Load event. Within a Load event handler, you are free to configure the look-and-feel of the Form, prepare any contained child controls (e.g., ListBoxes and TreeViews), or allocate resources used during the Form’s operation (e.g., database connections and proxies to remote objects). Once the Load event fires, the next event to fire is Activated. This event fires when the form receives the focus as the active window on the desktop. The logical counterpart to the Activated event is (of course) Deactivate, which fires when the form loses the focus as the active window. As you can guess, the Activated and Deactivate events can fire numerous times over the life of a given Form object as the user navigates between active windows and applications. Two events fire when the user chooses to close a given form: FormClosing and FormClosed. The FormClosing event is fired first and is an ideal place to prompt the end user with the much hated (but useful) message: “Are you sure you wish to close this application?” This step gives the user a chance to save any application-centric data before terminating the program. The FormClosing event works in conjunction with the FormClosingEventHandler delegate. If you set the FormClosingEventArgs.Cancel property to true, you prevent the window from being destroyed and instruct it to return to normal operation. If you set FormClosingEventArgs.Cancel to false, the FormClosed event fires, and the Windows Forms application exits, which unloads the AppDomain and terminates the process. This snippet updates your form’s constructor and handles the Load, Activated, Deactivate, FormClosing, and FormClosed events (you might recall from Chapter 11 that the IDE will autogenerate the correct delegate and event handler when you press the Tab key twice after typing +=): public MainWindow() {

1531

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

InitializeComponent();

// Handle various lifetime events. FormClosing += new FormClosingEventHandler(MainWindow_Closing); Load += new EventHandler(MainWindow_Load); FormClosed += new FormClosedEventHandler(MainWindow_Closed); Activated += new EventHandler(MainWindow_Activated); Deactivate += new EventHandler(MainWindow_Deactivate); } Within the Load, FormClosed, Activated, and Deactivate event handlers, you must update the value of a new Form-level string member variable (named lifeTimeInfo) with a simple message that displays the name of the event that has just been intercepted. Begin by adding this member to your Form derived class:

public partial class MainWindow : Form { private string lifeTimeInfo = ""; ... } The next step is to implement the event handlers. Notice that you display the value of the lifeTimeInfo string within a message box in the FormClosed event handler:

private void MainWindow_Load(object sender, System.EventArgs e) { lifeTimeInfo += "Load event\n"; }

private void MainWindow_Activated(object sender, System.EventArgs e) { lifeTimeInfo += "Activate event\n"; }

private void MainWindow_Deactivate(object sender, System.EventArgs e) { lifeTimeInfo += "Deactivate event\n"; }

private void MainWindow_Closed(object sender, FormClosedEventArgs e) { lifeTimeInfo += "FormClosed event\n"; MessageBox.Show(lifeTimeInfo); } Within the FormClosing event handler, you prompt the user to ensure that she wishes to terminate the application using the incoming FormClosingEventArgs. In the following code, the MessageBox.Show() method returns a DialogResult type that contains a value representing which button has been selected by the end user. Here, you craft a message box that displays Yes and No buttons; therefore, you want to discover whether the return value from Show() is DialogResult.No:

private void MainWindow_Closing(object sender, FormClosingEventArgs e) {

1532

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

lifeTimeInfo += "FormClosing event\n";

// Show a message box with Yes and No buttons. DialogResult dr = MessageBox.Show("Do you REALLY want to close this app?", "Closing event!", MessageBoxButtons.YesNo);

// Which button was clicked? if (dr == DialogResult.No) e.Cancel = true; else e.Cancel = false; }

Let’s make one final adjustment. Currently, the File ➤ Exit menu destroys the entire application, which is a bit aggressive. More often, the File ➤ Exit handler of a top-most window calls the inherited Close() method, which fires the close-centric events and then tears down the application: private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // Application.Exit(); Close(); }

Now run your application and shift the form into and out of focus a few times (to trigger the Activated and Deactivate events). When you eventually shut down the application, you will see a message box that looks something like the message shown in Figure A-12.

Figure A-12. The life and times of a Form-derived type

■ Source Code You can find the SimpleVSWinFormsApp project under the Appendix A subdirectory.

1533

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Responding to Mouse and Keyboard Activity You might recall that the Control parent class defines a set of events that allow you to monitor mouse and keyboard activity in a variety of manners. To check this out firsthand, create a new Windows Forms Application project named MouseAndKeyboardEventsApp, rename the initial form to MainWindow.cs (using the Solution Explorer), and handle the MouseMove event using the Properties window. These steps generate the following event handler:

public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); }

// Generated via the Properties window. private void MainWindow_MouseMove(object sender, MouseEventArgs e) { } }

The MouseMove event works in conjunction with the System.Windows.Forms.MouseEventHandler delegate. This delegate can only call methods where the first parameter is a System.Object, while the second is of type MouseEventArgs. This type contains various members that provide detailed information about the state of the event when mouse-centric events occur:

public class MouseEventArgs : EventArgs { public MouseEventArgs(MouseButtons button, int clicks, int x, int y, int delta);

public MouseButtons Button { get; } public int Clicks { get; } public int Delta { get; } public Point Location { get; } public int X { get; } public int Y { get; } }

Most of the public properties are self-explanatory, but Table A-8 provides more specific details.

Table A-8. Properties of the MouseEventArgs Type

Property Meaning in Life

Button Gets which mouse button was pressed, as defined by the MouseButtons enumeration.

Clicks Gets the number of times the mouse button was pressed and released.

1534

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-8. Properties of the MouseEventArgs Type (continued)

Property Meaning in Life

Delta Gets a signed count of the number of detents (which represents a single notch of the mouse wheel) for the current mouse rotation.

Location Returns a Point that contains the current X and Y location of the mouse.

X Gets the x-coordinate of a mouse click.

Y Gets the y-coordinate of a mouse click.

Now it’s time to implement your MouseMove handler to display the current X- and Y-position of the mouse on the Form’s caption; you do this using the Location property: private void MainWindow_MouseMove(object sender, MouseEventArgs e) { Text = string.Format("Mouse Position: {0}", e.Location); }

When you run the application and move the mouse over the window, you find the position displayed on the title area of your MainWindow type (see Figure A-13).

Figure A-13. Intercepting mouse movements

Determining Which Mouse Button Was Clicked Another common mouse-centric detail to attend to is determining which button has been clicked when a MouseUp, MouseDown, MouseClick, or MouseDoubleClick event occurs. When you wish to determine exactly which button was clicked (whether left, right, or middle), you need to examine the Button property of the MouseEventArgs class. The value of the Button property is constrained by the related MouseButtons enumeration: public enum MouseButtons { Left,

1535

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Middle, None, Right, XButton1, XButton2 }

■ Note The XButton1 and XButton2 values allow you to capture forward and backwards navigation buttons that are supported on many mouse-controller devices.

You can see this in action by handling the MouseDown event on your MainWindow type using the Properties window. The following MouseDown event handler displays which mouse button was clicked inside a message box:

private void MainWindow_MouseDown (object sender, MouseEventArgs e) { // Which mouse button was clicked? if(e.Button == MouseButtons.Left) MessageBox.Show("Left click!"); if(e.Button == MouseButtons.Right) MessageBox.Show("Right click!"); if (e.Button == MouseButtons.Middle) MessageBox.Show("Middle click!"); }

Determining Which Key Was Pressed Windows applications typically define numerous input controls (e.g., the TextBox) where the user can enter information using the keyword. When you capture keyboard input in this manner, you do not need to handle keyboard events explicitly because you can extract the textual data from the control using various properties (e.g., the Text property of the TextBox type). However, if you need to monitor keyboard input for more exotic purposes (e.g., filtering keystrokes on a control or capturing keypresses on the form itself), the base class libraries provide the KeyUp and KeyDown events. These events work in conjunction with the KeyEventHandler delegate, which can point to any method taking an object as the first parameter and KeyEventArgs as the second. You define this type like this:

public class KeyEventArgs : EventArgs { public KeyEventArgs(Keys keyData);

public virtual bool Alt { get; } public bool Control { get; } public bool Handled { get; set; } public Keys KeyCode { get; } public Keys KeyData { get; }

1536

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

public int KeyValue { get; } public Keys Modifiers { get; } public virtual bool Shift { get; } public bool SuppressKeyPress { get; set; } }

Table A-9 documents some of the more interesting properties supported by KeyEventArgs.

Table A-9. Properties of the KeyEventArgs Type

Property Meaning in Life

Alt Gets a value that indicates whether the Alt key was pressed.

Control Gets a value that indicates whether the Ctrl key was pressed.

Handled Gets or sets a value that indicates whether the event was fully handled in your handler.

KeyCode Gets the keyboard code for a KeyDown or KeyUp event.

Modifiers Indicates which modifier keys (e.g., Ctrl, Shift, and/or Alt) were pressed.

Shift Gets a value that indicates whether the Shift key was pressed.

You can see this in action by handling the KeyDown event as follows: private void MainWindow_KeyDown(object sender, KeyEventArgs e) { Text = string.Format("Key Pressed: {0} Modifiers: {1}", e.KeyCode.ToString(), e.Modifiers.ToString()); }

Now compile and run your program. You should be able to determine which mouse button was clicked, as well as which keyboard key was pressed. For example, Figure A-14 shows the result of pressing the Ctrl and Shift keys simultaneously.

Figure A-14. Intercepting keyboard activity

1537

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

■ Source Code You can find the MouseAndKeyboardEventsApp project under the Appendix A subdirectory.

Designing Dialog Boxes Within a program, dialog boxes tend to be the primary way to capture user input for use within the application itself. Unlike other GUI APIs you might have used previously, there Windows Forms has no Dialog base class. Rather, dialog boxes under Windows Forms are simply types that derive from the Form class. In addition, many dialog boxes are intended to be nonsizable; therefore, you typically want to set the FormBorderStyle property to FormBorderStyle.FixedDialog. Also, dialog boxes typically set the MinimizeBox and MaximizeBox properties to false. In this way, the dialog box is configured to be a fixed constant. Finally, if you set the ShowInTaskbar property to false, you will prevent the form from being visible in the Windows taskbar. Let’s look at how to build and manipulate dialog boxes. Begin by creating a new Windows Forms Application project named CarOrderApp and rename the initial Form1.cs file to MainWindow.cs using Solution Explorer. Next, use the Forms designer to create a simple File ➤ Exit menu, as well as a Tool ➤ Order Automobile... menu item (remember: you create a menu by dragging a MenuStrip from the Toolbox and then configuring the menu items in the designer window). Once you do this, handle the Click event for the Exit and Order Automobile submenus using the Properties window. You implement the File ➤ Exit menu handler so it terminates the application with a call to Close():

private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Close(); }

Now use the Project menu of Visual Studio to select the Add Windows Forms menu option and name your new form OrderAutoDialog.cs (see Figure A-15). For this example, design a dialog box that has the expected OK and Cancel buttons (named btnOK and btnCancel, respectively), as well as three TextBox controls named txtMake, txtColor, and txtPrice. Now use the Properties window to finalize the design of your dialog box, as follows: • Set the FormBorderStyle property to FixedDialog. • Set the MinimizeBox and MaximizeBox properties to false. • Set the StartPosition property to CenterParent. • Set the ShowInTaskbar property to false.

1538

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-15. Inserting new dialog boxes using Visual Studio

The DialogResult Property Finally, select the OK button and use the Properties window to set the DialogResult property to OK. Similarly, you can set the DialogResult property of the Cancel button to (you guessed it) Cancel. As you will see in a moment, the DialogResult property is quite useful because it enables the launching form to determine quickly which button the user has clicked; this enables you to take the appropriate action. You can set the DialogResult property to any value from the related DialogResult enumeration: public enum DialogResult { Abort, Cancel, Ignore, No, None, OK, Retry, Yes }

Figure A-16 shows one possible design of your dialog box; it even adds in a few descriptive controls.

1539

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-16. The OrderAutoDialog type

Configuring the Tab Order You have created a somewhat interesting dialog box; the next step is formalize the tab order. As you might know, users expect to be able to shift focus using the Tab key when a form contains multiple GUI widgets. Configuring the tab order for your set of controls requires that you understand two key properties: TabStop and TabIndex. You can set the TabStop property to true or false, based on whether or not you wish this GUI item to be reachable using the Tab key. Assuming that you set the TabStop property to true for a given control, you can use the TabOrder property to establish the order of activation in the tabbing sequence (which is zero-based), as in this example:

// Configure tabbing properties. txtMake.TabIndex = 0; txtMake.TabStop = true;

The Tab Order Wizard You can set the TabStop and TabIndex manually using the Properties window; however, the Visual Studio 2010 IDE supplies a Tab Order Wizard that you can access by choosing View ➤ Tab Order (be aware that you will not find this menu option unless the Forms designer is active). Once activated, your design-time form displays the current TabIndex value for each widget. To change these values, click each item in the order you prefer the controls to tab (see Figure A-17).

1540

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-17. The Tab Order Wizard

You can exit the Tab Order Wizard by pressing the Esc key.

Setting the Form’s Default Input Button Many user-input forms (especially dialog boxes) have a particular button that automatically responds to the user pressing the Enter key. Now assume that you want the Click event handler for btnOK invoked when the user presses the Enter key. Doing so is as simple as setting the form’s AcceptButton property as follows (you can establish this same setting using the Properties window): public partial class OrderAutoDialog : Form { public OrderAutoDialog() { InitializeComponent();

// When the Enter key is pressed, it is as if // the user clicked the btnOK button. this.AcceptButton = btnOK; } }

■ Note Some forms require the ability to simulate clicking the form’s Cancel button when the user presses the Esc key. You can accomplish this by assigning the CancelButton property of the Form to the Button object that represents the clicking of the Cancel button.

1541

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Displaying Dialog Boxes When you wish to display a dialog box, you must first decide whether you wish to launch the dialog box in a modal or modeless fashion. As you might know, modal dialog boxes must be dismissed by the user before he can return to the window that launched the dialog box in the first place; for example, most About boxes are modal in nature. To show a modal dialog box, call ShowDialog() off your dialog box object. On the other hand, you can display a modeless dialog box by calling Show(), which allows the user to switch focus between the dialog box and the main window (e.g., a Find/Replace dialog box). For this example, you want to update the Tools ➤ Order Automobile... menu handler of the MainWindow type to show the OrderAutoDialog object in a modal manner. Consider the following initial code:

private void orderAutomobileToolStripMenuItem_Click(object sender, EventArgs e) { // Create your dialog object. OrderAutoDialog dlg = new OrderAutoDialog();

// Show as modal dialog box, and figure out which button // was clicked using the DialogResult return value. if (dlg.ShowDialog() == DialogResult.OK) { // They clicked OK, so do something... } }

■ Note You can optionally call the ShowDialog() and Show() methods by specifying an object that represents the owner of the dialog box (which for the form loading the dialog box would be represented by this). Specifying the owner of a dialog box establishes the z-ordering of the form types and also ensures (in the case of a modeless dialog box) that all owned windows are also disposed of when the main window is destroyed.

Be aware that when you create an instance of a Form-derived type (OrderAutoDialog in this case), the dialog box is not visible on the screen, but simply allocated into memory. It is not until you call Show() or ShowDialog() that the form becomes visible. Also, notice that ShowDialog() returns the DialogResult value that has been assigned to the button (the Show() method simply returns void). Once ShowDialog() returns, the form is no longer visible on the screen, but is still in memory. This means you can extract the values in each TextBox. However, you will receive compiler errors if you attempt to compile the following code:

private void orderAutomobileToolStripMenuItem_Click(object sender, EventArgs e) { // Create your dialog object. OrderAutoDialog dlg = new OrderAutoDialog();

// Show as modal dialog box, and figure out which button

1542

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

// was clicked using the DialogResult return value. if (dlg.ShowDialog() == DialogResult.OK) { // Get values in each ? Compiler errors! string orderInfo = string.Format("Make: {0}, Color: {1}, Cost: {2}", dlg.txtMake.Text, dlg.txtColor.Text, dlg.txtPrice.Text); MessageBox.Show(orderInfo, "Information about your order!"); } }

The reason you get compiler errors is that Visual Studio 2010 declares the controls you add to the Forms designer as private member variables of the class! You can verify this fact by opening the OrderAutoDialog.Designer.cs file. While a prim-and-proper dialog box might preserve encapsulation by adding public properties to get and set the values within these text boxes, you can take a shortcut and redefine them by using the public keyword. To do so, select each TextBox on the designer, and then set the Modifiers property of the control to Public using the Properties window. This changes the underlying designer code: partial class OrderAutoDialog { ... // Form member variables are defined within the designer-maintained file. public System.Windows.Forms.TextBox txtMake; public System.Windows.Forms.TextBox txtColor; public System.Windows.Forms.TextBox txtPrice; }

At this point, you can compile and run your application. Once you launch your dialog box, you should be able to see the input data displayed within a message box (provided you click the OK button).

Understanding Form Inheritance So far, each one of your custom windows/dialog boxes in this chapter has derived directly from System.Windows.Forms.Form. However, one intriguing aspect of Windows Forms development is the fact that Form types can function as the base class to derived Forms. For example, assume you create a .NET code library that contains each of your company’s core dialog boxes. Later, you decide that your company’s About box is a bit on the bland side, and you wish to add a 3D image of your company logo. Rather than having to re-create the entire About box, you can extend the basic About box, thereby inheriting the core look-and-feel:

// ThreeDAboutBox "is-a" AboutBox public partial class ThreeDAboutBox : AboutBox { // Add code to render company logo... }

To see form inheritance in action, insert a new form into your project using the Project ➤ Add Windows Form menu option. This time, however, pick the Inherited Form icon, and name your new form ImageOrderAutoDialog.cs (see Figure A-18).

1543

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-18. Adding a derived form to your project

This option brings up the Inheritance Picker dialog box, which shows you each of the forms in your current project. Notice that the Browse button allows you to pick a form in an external .NET assembly. Here, simply pick your OrderAutoDialog class.

■ Note You must compile your project at least one time to see the forms of your project in the Inheritance Picker dialog box because this tool reads from the assembly to show you your options.

Once you click the OK button, the visual designer tools show each of the base controls on your parent controls; each control has a small arrow icon mounted on the upper-left of the control (symbolizing inheritance). To complete your derived dialog box, locate the PictureBox control from the Common Controls section of the Toolbox and add one to your derived form. Next, use the Image property to select an image file of your choosing. Figure A-19 shows one possible UI, using a (crude) hand drawing of a junker automobile (a lemon!).

1544

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-19. The UI of the ImageOrderAutoDialog class

With this, you can now update the Tools ➤ Order Automobile... Click event handler to create an instance of your derived type, rather than the OrderAutoDialog base class: private void orderAutomobileToolStripMenuItem_Click(object sender, EventArgs e) { // Create the derived dialog object. ImageOrderAutoDialog dlg = new ImageOrderAutoDialog(); ... }

■ Source Code You can find the CarOrderApp project under the Appendix A subdirectory.

Rendering Graphical Data Using GDI+ Many GUI applications require the ability to generate graphical data dynamically for display on the surface of a window. For example, perhaps you have selected a set of records from a relational database and wish to render a pie chart (or bar chart) that visually shows items in stock. Or, perhaps you want to re-create some old-school video game using the .NET platform. Regardless of your goal, GDI+ is the API to use when you need to render data graphically within a Windows Forms application. This technology is bundled within the System.Drawing.dll assembly, which defines a number of namespaces (see Figure A-20).

1545

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-20. The namespaces of System.Drawing.dll

■ Note A friendly reminder: WPF has its own graphical rendering subsystem and API; you use GDI+ only within a Windows Forms application.

Table A-10 documents the role of the key GDI+ namespaces at a high level.

Table A-10. Core GDI+ Namespaces

Namespace Meaning in Life

System.Drawing This is the core GDI+ namespace that defines numerous types for basic rendering (e.g., fonts, pens, and basic brushes), as well as the almighty Graphics type.

System.Drawing.Drawing2D This namespace provides types used for more advanced 2D/vector graphics functionality (e.g., gradient brushes, pen caps, and geometric transforms).

System.Drawing.Imaging This namespace defines types that allow you to manipulate graphical images (e.g., change the palette, extract image metadata, manipulate metafiles, etc.).

System.Drawing.Printing This namespace defines types that allow you to render images to the printed page, interact with the printer itself, and format the overall appearance of a given print job.

System.Drawing.Text This namespace allows you to manipulate collections of fonts.

1546

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

The System.Drawing Namespace You can find the vast majority of the types you’ll use when programming GDI+ applications in the System.Drawing namespace. As you might expect, you can find classes that represent images, brushes, pens, and fonts. System.Drawing also defines a several related utility types, such as Color, Point, and Rectangle. Table A-11 lists some (but not all) of the core types.

Table A-11. Core Types of the System.Drawing Namespace

Type Meaning in Life

Bitmap This type encapsulates image data (*.bmp or otherwise).

Brush You use brush objects to fill the interiors of graphical shapes, such as rectangles, Brushes ellipses, and polygons. SolidBrush SystemBrushes TextureBrush

BufferedGraphics This type provides a graphics buffer for double buffering, which you use to reduce or eliminate flicker caused by redrawing a display surface.

Color The Color and SystemColors types define a number of static read-only properties SystemColors you use to obtain specific colors for the construction of various pens/brushes.

Font The Font type encapsulates the characteristics of a given font (e.g., type name, FontFamily bold, italic, and point size). FontFamily provides an abstraction for a group of fonts that have a similar design, but also certain variations in style.

Graphics This core class represents a valid drawing surface, as well as several methods to render text, images, and geometric patterns.

Icon These classes represent custom icons, as well as the set of standard system- SystemIcons supplied icons.

Image Image is an abstract base class that provides functionality for the Bitmap, Icon, ImageAnimator and Cursor types. ImageAnimator provides a way to iterate over a number of Image-derived types at some specified interval.

Pen Pens are objects you use to draw lines and curves. The Pens type defines several Pens static properties that return a new Pen of a given color. SystemPens

Point These structures represent an (x, y) coordinate mapping to an underlying integer PointF or float, respectively.

1547

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-11. Core Types of the System.Drawing Namespace (continued)

Type Meaning in Life

Rectangle These structures represent a rectangular dimension (again, these map to an RectangleF underlying integer or float).

Size These structures represent a given height/width (again, these map to an underlying SizeF integer or float).

StringFormat You use this type to encapsulate various features of textual layout (e.g., alignment and line spacing).

Region This type describes the interior of a geometric image composed of rectangles and paths.

The Role of the Graphics Type The System.Drawing.Graphics class serves as the gateway to GDI+ rendering functionality. This class not only represents the surface you wish to draw upon (such as a form’s surface, a control’s surface, or a region of memory), but also defines dozens of members that allow you to render text, images (e.g., icons and bitmaps), and numerous geometric patterns. Table A-12 gives a partial list of members.

Table A-12. Select Members of the Graphics Class

Method Meaning in Life

FromHdc() These static methods provide a way to obtain a valid Graphics object from a FromHwnd() given image (e.g., icon and bitmap) or GUI control. FromImage()

Clear() This method fills a Graphics object with a specified color, erasing the current drawing surface in the process.

DrawArc() You use these methods to render a given image or geometric pattern. DrawBeziers() All DrawXXX() methods require that you use GDI+ Pen objects. DrawCurve() DrawEllipse() DrawIcon() DrawLine() DrawLines() DrawPie() DrawPath() DrawRectangle() DrawRectangles() DrawString()

1548

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Table A-12. Select Members of the Graphics Class (continued)

Method Meaning in Life

FillEllipse() You use these methods to fill the interior of a given geometric shape. FillPie() All FillXXX() methods require that you use GDI+ Brush objects. FillPolygon() FillRectangle() FillPath()

Note that you cannot create the Graphics class directly using the new keyword because there are no publicly defined constructors. So, how do you obtain a valid Graphics object? I’m glad you asked!

Obtaining a Graphics Object with the Paint Event The most common way to obtain a Graphics object is to use the Visual Studio 2010 Properties window to handle the Paint event on the window you want to render upon. This event is defined in terms of the PaintEventHandler delegate, which can point to any method taking a System.Object as the first parameter and a PaintEventArgs as the second. The PaintEventArgs parameter contains the Graphics object you need to render onto the Form’s surface. For example, create a new Windows Application project named PaintEventApp. Next, use Solution Explorer to rename your initial Form.cs file to MainWindow.cs, and then handle the Paint event using the Properties window. This creates the following stub code: public partial class MainWindow : Form { public MainWindow() { InitializeComponent(); }

private void MainWindow_Paint(object sender, PaintEventArgs e) { // Add your painting code here! } } Now that you have handled the Paint event, you might wonder when it will fire. The Paint event fires whenever a window becomes dirty; a window is considered dirty whenever it is resized, uncovered by another window (partially or completely), or minimized and then restored. In all these cases, the .NET platform ensures that the Paint event handler is called automatically whenever your Form needs to be redrawn. Consider the following implementation of MainWindow_Paint(): private void MainWindow_Paint(object sender, PaintEventArgs e) { // Get the graphics object for this Form. Graphics g = e.Graphics;

// Draw a circle. g.FillEllipse(Brushes.Blue, 10, 20, 150, 80);

1549

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

// Draw a string in a custom font. g.DrawString("Hello GDI+", new Font("Times New Roman", 30), Brushes.Red, 200, 200);

// Draw a line with a custom pen. using (Pen p = new Pen(Color.YellowGreen, 10)) { g.DrawLine(p, 80, 4, 200, 200); } } Once you obtain the Graphics object from the incoming PaintEventArgs parameter, you call FillEllipse(). Notice that this method (as well as any Fill-prefixed method) requires a Brush-derived type as the first parameter. While you could create any number of interesting brush objects from the System.Drawing.Drawing2D namespace (e.g., HatchBrush and LinearGradientBrush), the Brushes utility class provides handy access to a variety of solid-colored brush types. Next, you make a call to DrawString(), which requires a string to render as its first parameter. Given this, GDI+ provides the Font type, which represents not only the name of the font to use when rendering the textual data, but also related characteristics, such as the point size (30, in this case). Also notice that DrawString() requires a Brush type; as far as GDI+ is concerned, “Hello GDI+” is nothing more than a collection of geometric patterns to fill on the screen. Finally, DrawLine() is called to render a line using a custom Pen type, 10 pixels wide. Figure A-21 shows the output of this rendering logic.

Figure A-21. A simple GDI+ rendering operation

■ Note In the preceding code, you explicitly dispose of the Pen object. As a rule, when you directly create a GDI+ type that implements IDisposable, you call the Dispose() method as soon as you are done with the object. Doing this lets you release the underlying resources as soon as possible. If you do not do this, the resources will eventually be freed by the garbage collector in a nondeterministic manner.

1550

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Invalidating the Form’s Client Area During the flow of a Windows Forms application, you might need to fire the Paint event in your code explicitly, rather than waiting for the window to become naturally dirty by the actions of the end user. For example, you might be building a program that allows the user to select from a number of predefined images using a custom dialog box. Once the dialog box is dismissed, you need to draw the newly selected image onto the form’s client area. Obviously, if you were to wait for the window to become naturally dirty, the user would not see the change take place until the window was resized or uncovered by another window. To force a window to repaint itself programmatically, you call the inherited Invalidate() method: public partial class MainForm: Form { ... private void MainForm_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; // Render the correct image here. }

private void GetImageFromDialog() { // Show dialog box and get new image. // Repaint the entire client area. Invalidate(); } }

The Invalidate() method has been overloaded a number of times. This allows you to specify a specific rectangular portion of the form to repaint, rather than having to repaint the entire client area (which is the default). If you wish to update only the extreme upper-left rectangle of the client area, you can write the following code:

// Repaint a given rectangular area of the Form. private void UpdateUpperArea() { Rectangle myRect = new Rectangle(0, 0, 75, 150); Invalidate(myRect); }

■ Source Code You can find the PaintEventApp project under the Appendix A subdirectory.

Building a Complete Windows Forms Application Let’s conclude this introductory look at the Windows Forms and GDI+ APIs by building a complete GUI application that illustrates several of the techniques discussed in this chapter. The program you will create is a rudimentary painting program that allows users to select between two shape types (a circle or

1551

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

rectangle) using the color of their choice to render data to the form. You will also allow end users to save their pictures to a local file on their hard drive for later use with object services.

Building the Main Menu System Begin by creating a new Windows Forms application named MyPaintProgram and rename your initial Form1.cs file to MainWindow.cs. Now design a menu system on this initial window that supports a topmost File menu that provides Save..., Load..., and Exit submenus (see Figure A-22).

Figure A-22. The File menu system

■ Note If you specify a single dash (-) as a menu item, you can define separators within your menu system.

Next, create a second topmost Tools menu that provides options to select a shape and color to use for rendering, as well as an option to clear the form of all graphical data (see Figure A-23).

Figure A-23. The Tools Menu System

1552

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Finally, handle the Click event for each one of these subitems. You will implement each handler as you progress through the example; however, you can finish up the File ➤ Exit menu handler by calling Close(): private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Close(); }

Defining the ShapeData Type Recall that this application will allow end users to select from two predefined shapes in a given color. You will provide a way to allow users to save their graphical data to a file, so you want to define a custom class type that encapsulates each of these details; for the sake of simplicity, you do this using C# automatic properties (see Chapter 5 for more details on how to do this). Begin by adding a new class to your project named ShapeData.cs and implementing this type as follows:

[Serializable] class ShapeData { // The upper left of the shape to be drawn. public Point UpperLeftPoint { get; set; }

// The current color of the shape to be drawn. public Color Color { get; set; }

// The type of shape. public SelectedShape ShapeType { get; set; } }

Here, ShapeData uses three automatic properties that encapsulates various types of data, two of which (Point and Color) are defined in the System.Drawing namespace, so be sure to import this namespace into your code file. Also, notice that this type has been adorned with the [Serializable] attribute. In an upcoming step, you will configure your MainWindow type to maintain a list of ShapeData types that you persist using object serialization services (see Chapter 20 for more details).

Defining the ShapePickerDialog Type You can allow the user to choose between the circle or rectangle image type by creating a simple custom dialog box named ShapePickerDialog (insert this new Form now). Beyond adding the obligatory OK and Cancel buttons (each of which you should assign fitting DialogResult values), this dialog box uses of a single GroupBox that maintains two RadioButton objects: radioButtonCircle and radioButtonRect. Figure A-24 shows one possible design.

1553

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-24. The ShapePickerDialog type

Now, open the code window for your dialog box by right-clicking the Forms designer and selecting the View Code menu option. Within the MyPaintProgram namespace, define an enumeration (named SelectedShape) that defines names for each possible shape:

public enum SelectedShape { Circle, Rectangle } Next, update your current ShapePickerDialog class type: • Add an automatic property of type SelectedShape. The caller can use this property to determine which shape to render. • Handle the Click event for the OK button using the Properties window. • Implement this event handler to determine whether the circle has been selected (through the Checked property). If so, set your SelectedShape property to SelectedShape.Circle; otherwise, set this property to SelectedShape.Rectangle. Here is the complete code:

public partial class ShapePickerDialog : Form { public SelectedShape SelectedShape { get; set; }

public ShapePickerDialog() { InitializeComponent(); }

private void btnOK_Click(object sender, EventArgs e) { if (radioButtonCircle.Checked) SelectedShape = SelectedShape.Circle; else

1554

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

SelectedShape = SelectedShape.Rectangle; } }

That wraps up the infrastructure of your program. Now all you need to do is implement the Click event handlers for the remaining menu items on the main window.

Adding Infrastructure to the MainWindow Type Returning to the construction of the main window, add three new member variables to this Form. These member variables allow you to keep track of the selected shape (through a SelectedShape enum member variable), the selected color (represented by a System.Drawing.Color member variable), and through each of the rendered images held in a generic List (where T is of type ShapeData): public partial class MainWindow : Form { // Current shape / color to draw. private SelectedShape currentShape; private Color currentColor = Color.DarkBlue;

// This maintains each ShapeData. private List shapes = new List(); ... }

Next, you handle the MouseDown and Paint events for this Form-derived type using the Properties window. You will implement them in a later step; for the time being, however, you should find that the IDE has generated the following stub code: private void MainWindow_Paint(object sender, PaintEventArgs e) { } private void MainWindow_MouseDown(object sender, MouseEventArgs e) { }

Implementing the Tools Menu Functionality You can allow a user to set the currentShape member variable by implementing the Click handler for the Tools ➤ Pick Shape... menu option. You use this to launch your custom dialog box; based on a user’s selection, you assign this member variable accordingly: private void pickShapeToolStripMenuItem_Click(object sender, EventArgs e) { // Load our dialog box and set the correct shape type. ShapePickerDialog dlg = new ShapePickerDialog(); if (DialogResult.OK == dlg.ShowDialog()) {

1555

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

currentShape = dlg.SelectedShape; } }

You can let a user set the currentColor member variable by implementing the Click event handler for the Tools ➤ Pick Color... menu so it uses the System.Windows.Forms.ColorDialog type:

private void pickColorToolStripMenuItem_Click(object sender, EventArgs e) { ColorDialog dlg = new ColorDialog();

if (dlg.ShowDialog() == DialogResult.OK) { currentColor = dlg.Color; } }

If you were to run your program as it now stands and select the Tools ➤ Pick Color menu option, you would get the dialog box shown in Figure A-25.

Figure A-25. The stock ColorDialog type

Finally, you implement the Tools ➤ Clear Surface menu handler so it empties the contents of the List member variable and programmatically fires the Paint event using a call to Invalidate():

private void clearSurfaceToolStripMenuItem_Click(object sender, EventArgs e) { shapes.Clear();

// This will fire the paint event. Invalidate(); }

1556

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Capturing and Rendering the Graphical Output Given that a call to Invalidate() fires the Paint event, you need to author code within the Paint event handler. Your goal is to loop through each item in the (currently empty) List member variable and render a circle or square at the current mouse location. The first step is to implement the MouseDown event handler and insert a new ShapeData type into the generic List type, based on the user-selected color, shape type, and current location of the mouse: private void MainWindow_MouseDown(object sender, MouseEventArgs e) { // Make a ShapeData type based on current user // selections. ShapeData sd = new ShapeData(); sd.ShapeType = currentShape; sd.Color = currentColor; sd.UpperLeftPoint = new Point(e.X, e.Y);

// Add to the List and force the form to repaint itself. shapes.Add(sd); Invalidate(); }

At this point, you can implement your Paint event handler: private void MainWindow_Paint(object sender, PaintEventArgs e) { // Get the Graphics object for this window. Graphics g = e.Graphics;

// Render each shape in the selected color. foreach (ShapeData s in shapes) { // Render a rectangle or circle 20 x 20 pixels in size // using the correct color. if (s.ShapeType == SelectedShape.Rectangle) g.FillRectangle(new SolidBrush(s.Color), s.UpperLeftPoint.X, s.UpperLeftPoint.Y, 20, 20); else g.FillEllipse(new SolidBrush(s.Color), s.UpperLeftPoint.X, s.UpperLeftPoint.Y, 20, 20); } }

If you run your application at this point, you should be able to render any number of shapes in a variety of colors (see Figure A-26).

1557

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Figure A-26. MyPaintProgram in action

Implementing the Serialization Logic The final aspect of this project involves implementing Click event handlers for the File ➤ Save... and File ➤ Load... menu items. Given that ShapeData has been marked with the [Serializable] attribute (and given that List itself is serializable), you can quickly save out the current graphical data using the Windows Forms SaveFileDialog type. Begin by updating your using directives to specify you are using the System.Runtime.Serialization.Formatters.Binary and System.IO namespaces:

// For the binary formatter. using System.Runtime.Serialization.Formatters.Binary; using System.IO;

Now update your File ➤ Save... handler, as follows:

private void saveToolStripMenuItem_Click(object sender, EventArgs e) { using (SaveFileDialog saveDlg = new SaveFileDialog()) { // Configure the look and feel of the save dialog box. saveDlg.InitialDirectory = "."; saveDlg.Filter = "Shape files (*.shapes)|*.shapes"; saveDlg.RestoreDirectory = true; saveDlg.FileName = "MyShapes";

// If they click the OK button, open the new // file and serialize the List. if (saveDlg.ShowDialog() == DialogResult.OK) { Stream myStream = saveDlg.OpenFile(); if ((myStream != null)) { // Save the shapes!

1558

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

BinaryFormatter myBinaryFormat = new BinaryFormatter(); myBinaryFormat.Serialize(myStream, shapes); myStream.Close(); } } } }

The File ➤ Load event handler opens the selected file and deserializes the data back into the List member variable with the help of the Windows Forms OpenFileDialog type: private void loadToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog openDlg = new OpenFileDialog()) { openDlg.InitialDirectory = "."; openDlg.Filter = "Shape files (*.shapes)|*.shapes"; openDlg.RestoreDirectory = true; openDlg.FileName = "MyShapes";

if (openDlg.ShowDialog() == DialogResult.OK) { Stream myStream = openDlg.OpenFile(); if ((myStream != null)) { // Get the shapes! BinaryFormatter myBinaryFormat = new BinaryFormatter(); shapes = (List)myBinaryFormat.Deserialize(myStream); myStream.Close(); Invalidate(); } } } }

After Chapter 20, the overall serialization logic here should look familiar. It is worth pointing out that the SaveFileDialog and OpenFileDialog types both support a Filter property that is assigned a rather cryptic string value. This filter controls a number of settings for the save/open dialog boxes, such as the file extension (*.shapes). You use the FileName property to control what the default name of the file you want to create—MyShapes, in this example. At this point, your painting application is complete. You should now be able to save and load your current graphical data to any number of *.shapes files. If you want to enhance this Windows Forms program, you might wish to account for additional shapes, or even to allow the user to control the size of the shape to draw or perhaps select the format used to save the data (e.g., binary, XML, or SOAP; see Chapter 20).

1559

APPENDIX A ■ PROGRAMMING WITH WINDOWS FORMS

Summary This chapter examined the process of building traditional desktop applications using the Windows Forms and GDI+ APIs, which have been part of the .NET Framework since version 1.0. At minimum, a Windows Forms application consists of a type-extending Form and a Main() method that interacts with the Application type. When you want to populate your forms with UI elements (e.g., menu systems and GUI input controls), you do so by inserting new objects into the inherited Controls collection. This chapter also showed you how to capture mouse, keyboard, and rendering events. Along the way, you learned about the Graphics type and many ways to generate graphical data at runtime. As mentioned in this chapter’s overview, the Windows Forms API has been (in some ways) superseded by the WPF API introduced with the release of .NET 3.0 (which you learned about in some detail in Part 6 of this book). While it is true that WPF is the choice for supercharged UI front ends, the Windows Forms API remains the simplest (and in many cases, most direct) way to author standard business applications, in-house applications, and simple configuration utilities. For these reasons, Windows Forms will be part of the .NET base class libraries for years to come.

1560

A P P E N D I X B

■ ■ ■

Platform-Independent .NET Development with

This appendix introduces you to the topic of cross-platform C# and .NET development using an implementation of .NET named Mono (in case you are wondering about the name, mono is a Spanish word for monkey, which is a reference to the various monkey-mascots used by the initial creators of the Mono platform, Corporation). In this appendix, you will learn about the role of the Common Language Infrastructure (CLI), the overall scope of Mono, and various Mono development tools. At the conclusion of this appendix-and given your work over the course of this book—you will be in a perfect position to dig further into Mono development as you see fit.

■ Note If you require a detailed explanation of cross-platform .NET development, I recommend picking up a copy of Cross-Platform .NET Development: Using Mono, Portable .NET, and Microsoft .NET by Mark Easton and Jason King (Apress, 2004).

The Platform-Independent Nature of .NET Historically speaking, when programmers used a Microsoft development language (e.g., VB6) or Microsoft programming framework (e.g., MFC, COM, or ATL), they had to resign themselves to building software that (by-and-large) executed only on the Windows family of operating systems. Many .NET developers, accustomed to previous Microsoft development options, are frequently surprised when they learn that .NET is platform-independent. But it’s true. You can create, compile, and execute .NET assemblies on operating systems other than . Using open source .NET implementations such as Mono, your .NET applications can find happy homes on numerous operating systems, including Mac OS X, Solaris, AIX, and numerous flavors of /. Mono also provides an installation package for (surprise, surprise) Microsoft Windows. Thus, it is possible to build and run .NET assemblies on the Windows , without ever installing the Microsoft .NET Framework 4.0 SDK or the Visual Studio 2010 IDE.

1561

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

■ Note Be aware that the Microsoft .NET Framework 4.0 SDK and Visual Studio 2010 are your best options for building .NET software for the Windows family of operating systems.

Even after developers learn about .NET code’s cross-platform capabilities, they often assume that the scope of platform-independent .NET development is limited to little more than Hello World console applications. The reality is that you can build production-ready assemblies that use ADO.NET, Windows Forms (in addition to alternative GUI toolkits such as GTK# and Cocoa#), ASP.NET, LINQ, and XML web services by taking advantage of many of the core namespaces and language features you have seen featured throughout this book.

The Role of the CLI .NET’s cross-platform capabilities are implemented differently than the approach taken by Sun Microsystems and its handling of the Java programming platform. Unlike Java, Microsoft itself does not provide .NET installers for Mac, Linux, and so on. Rather, Microsoft has released a set of formalized specifications that other entities can use as a road map for building .NET distributions for their platform(s) of choice. Collectively, these specifications are termed the Common Language Infrastructure (CLI). As briefly mentioned in Chapter 1, Microsoft submitted two formal specifications to ECMA (European Computer Manufacturers Association) when it released C# and the .NET platform to the world at large. Once approved, Microsoft submitted these same specifications to the International Organization for Standardization (ISO), and these specifications were ratified shortly thereafter. So, why should you care? These two specifications provide a road map for other companies, developers, universities, and other organizations to build their own custom distributions of the C# and the .NET platform. The two specifications in question are: • ECMA-334: Defines the syntax and semantics of the C# programming language. • ECMA-335: Defines many details of the .NET platform, collectively called the Common Language Infrastructure. ECMA-334 tackles the lexical grammar of C# in an extremely rigorous and scientific manner (as you might guess, this level of detail is quite important to those who want to implement a C# compiler). However, ECMA-335 is the meatier of the two specifications, so much so that it has been broken down into six partitions (see Table B-1).

1562

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Table B-1. ECMA-335 Specification Partitions

ECMA-335 Partition Meaning in Life

Partition I: Concepts and Describes the overall architecture of the CLI, including the Architecture rules of the , the Common Language Specification, and the mechanics of the .NET runtime engine.

Partition II: Metadata Describes the details of the .NET metadata format. Definition and Semantics

Partition III: CIL Describes the syntax and semantics of the common Instruction Set intermediate language (CIL) programming language.

Partition IV: Profiles and Provides a high-level overview of the minimal and complete Libraries class libraries that must be supported by a CLI-compatible .NET distribution.

Partition V: Debug Provides details of the portable debug interchange format Interchange Formats (CILDB). Portable CILDB files provide a standard way to exchange debugging information between CLI producers and consumers.

Partition : Annexes Represents a collection of odds and ends; it clarifies topics such as class library design guidelines and the implementation details of a CIL compiler.

The point of this appendix is not to dive into the details of the ECMA-334 and ECMA-335 specifications—nor must you know the ins-and-outs of these documents to understand how to build platform-independent .NET assemblies. However, if you are interested, you can download both of these specifications for free from the ECMA website (http://www.ecma- international.org/publications/standards).

The Mainstream CLI Distributions To date, you can find two mainstream implementations of the CLI beyond Microsoft’s CLR, , and the Microsoft NET Compact Framework (see Table B-2).

1563

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Table B-2. Mainstream .NET CLI Distributions

CLI Distribution Supporting Website Meaning in Life

Mono www.mono-project.com Mono is an open source and commercially supported distribution of .NET sponsored by Corporation. Mono is targeted to run on many popular flavors of Unix/Linux, Mac OS X, Solaris, and Windows.

Portable .NET www.dotgnu.org Portable .NET is distributed under the GNU General Public License. As the name implies, Portable .NET intends to function on as many operation systems and architectures as possible, including esoteric platforms such as BeOS, Microsoft , and Sony PlayStation (no, I’m not kidding about the last two!).

Each of the CLI implementations shown in Table B-2 provide a fully function C# compiler, numerous command-line development tools, a (GAC) implementation, sample code, useful documentation, and dozens of assemblies that constitute the base class libraries. Beyond implementing the core libraries defined by Partition IV of ECMA-335, Mono and Portable .NET provide Microsoft-compatible implementations of mscorlib.dll, System.Core.dll, System.Data.dll, System.Web.dll, System.Drawing.dll, and System.Windows.Forms.dll (among many others). The Mono and Portable .NET distributions also ship with a handful of assemblies specifically targeted at Unix/Linux and Mac OS X operating systems. For example, Cocoa# is a .NET wrapper around the preferred Mac OX GUI toolkit, Cocoa. In this appendix, I will not dig into these OS-specific binaries; instead, I’ll focus on using the OS-agonistic programming stacks.

■ Note This appendix will not examine Portable .NET; however, it is important to know that Mono is not the only platform-independent distribution of the .NET platform available today. I recommend you take some time to play around with Portable .NET in addition to the Mono platform.

The Scope of Mono Given that Mono is an API built on existing ECMA specifications that originated from Microsoft, you would be correct in assuming that Mono is playing a constant game of catch up as newer versions of Microsoft’s .NET platform are released. At the time of this writing, Mono is compatible with C# 2008 (work on the new C# 2010 language features are in development as I type) and .NET 2.0. This means you can build ASP.NET websites, Windows Forms applications, database-centric applications using ADO.NET, and (of course) simple console applications.

1564

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Currently, Mono is not completely compatible with the new features of C# 2010 (e.g., optional arguments and the dynamic keyword) or with all aspects of .NET 3.0-4.0. This means that Mono applications are currently unable (again, at the time of this writing) to use the following Microsoft .NET APIs: • Windows Presentation Foundation (WPF) • Windows Communication Foundation (WCF) • Windows Workflow Foundation (WF) • LINQ to Entities (however, LINQ to Objects and LINQ to XML are supported) • Any C# 2010 specific language features Some of these APIs might eventually become part of the standard Mono distribution stacks. For example, according to the Mono website, future versions of the platform (2.8-3.0) will provide support for C# 2010 language features and .NET 3.5-4.0 platform features. In addition to keeping-step with Microsoft’s core .NET APIs and C# language features, Mono also provides an open source distribution of the Silverlight API named . This enables browsers that run under Linux based operating systems to host and use Silverlight / Moonlight web applications. As you might already know, Microsoft’s Silverlight already includes support for Mac OS X; and given the Moonlight API, this technology has truly become cross-platform. Mono also supports some .NET based technologies that do not have a direct Microsoft equivalent. For example, Mono ships with GTK#, a .NET wrapper around a popular Linux-centric GUI framework named GTK. One compelling Mono-centric API is MonoTouch, which allows you to build applications for Apple iPhone and iTouch devices using the C# programming language.

■ Note The Mono website includes a page that describes the overall road map of Mono’s functionality and the project’s plans for future releases (www.mono-project.com/plans).

A final point of interest regarding the Mono feature set: Much like Microsoft’s .NET Framework 4.0 SDK, the Mono SDK supports several .NET programming languages. While this appendix focuses on C#, Mono also provides support for a compiler, as well as support for many other .NET-aware programming languages.

Obtaining and Installing Mono Now that you have a better idea what you can do with the Mono platform, let’s turn our attention to obtaining and installing Mono itself. Navigate to the Mono website (www.mono-project.com) and locate the Download tab to navigate to the downloads page. Here you can download a variety of installers (see Figure B-1).

1565

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Figure B-1. The Mono Download Page

This appendix assumes that you are installing the Windows distribution of Mono (note that installing Mono will not interfere whatsoever with any existing installation of Microsoft .NET or Visual Studio IDEs). Begin by downloading the current, stable Mono installation package for Microsoft Windows and saving the setup program to your local hard drive. When you run the setup program, you are given a chance to install a variety of Mono development tools beyond the expected base class libraries and the C# programming tools. Specifically, the installer will ask you whether you wish to include GTK# (the open source .NET GUI API based on the Linux- centric GTK toolkit) and XSP (a stand-alone web , similar to Microsoft’s ASP.NET development web server [webdev.webserver.exe]). This appendix also assumes you have opted for a Full Installation, which selects each option in the setup script (see Figure B-2).

1566

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Figure B-2. Select All Options for Your Mono Installation

Examining Mono’s Directory Structure By default, Mono installs under C:\\Mono- (at the time of this writing, the latest version of Mono is 2.4.2.3; however, your version number will almost certainly be different). Beneath that root, you can find several subdirectories (see Figure B-3).

1567

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Figure B-3. The Mono Directory Structure

For this appendix, you need to concern yourself only with the following subdirectories: • bin: Contains a majority of the Mono development tools, including the C# command-line . • lib\mono\gac: Points to the location of Mono’s global assembly cache. Given that you run the vast majority of Mono’s development tools from the command line, you will want to use the Mono command prompt, which automatically recognizes each of the command-line development tools. You can activate the command prompt (which is functionally equivalent to the Visual Studio 2010 command prompt) by selecting Start ➤ All Programs ➤ Mono For Windows menu option. To test your installation, enter the following command and press the Enter key:

mono --version

If all is well, you should see various details regarding the Mono runtime environment. Here is the output on my Mono development machine:

1568

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Mono JIT compiler version 2.4.2.3 (tarball) Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com TLS: normal GC: Included Boehm (with typed GC) SIGSEGV: normal Notification: Thread + polling Architecture: Disabled: none

The Mono Development Languages Similar to the Microsoft’s CLR distribution, Mono ships with a number of managed compilers: • mcs: The Mono C# compiler • vbnc: The Mono Visual Basic .NET compiler • booc: The Mono Boo language compiler • : The Mono CIL compilers While this appendix focuses only on the C# compilers, you should keep in mind that the Mono project does ship with a Visual Basic compiler. While this tool is currently under development, the intended goal is to bring the world of human-readable keywords (e.g., Inherits, MustOverride, and Implements) to the world of Unix/Linux and Mac OS X (see www.mono-project.com/Visual_Basic for more details). Boo is an object-oriented, statically typed programming language for the CLI that sports a Python- based syntax. Check out http://boo.codehaus.org for more details on the Boo programming language. Finally, as you might have guessed, ilasm is the Mono CIL compiler.

Working with the C# Compiler The C# compiler for the Mono project was mcs, and it’s fully compatible with C# 2008. Like the Microsoft C# command-line compiler (csc.exe), mcs supports response files, a /target: flag (to define the assembly type), an /out: flag (to define the name of the compiled assembly), and a /reference: flag (to update the of the current assembly with external dependencies). You can view all the options of mcs using the following command: mcs -?

Building Mono Applications using MonoDevelop When you install Mono, you will not be provided with a graphical IDE. However, this does not mean you must build all of your Mono applications at the command prompt! In addition to the core framework, you can also download the free MonoDevelop IDE. As its name suggests, MonoDevelop was built using the core code base of SharpDevelop (see Chapter 2).

1569

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

You can download the MonoDevelop IDE from the Mono website, and it supports installation packages for Mac OS X, various Linux distributions, and (surprise!) Microsoft Windows! Once installed, you might be pleased to find an integrated , IntelliSense capabilities, numerous project templates (e.g., ASP.NET and Moonlight). You can get a taste of what the MonoDevelop IDE brings to the table by perusing Figure B-4.

Figure B-4. The MonoDevelop IDE Microsoft-Compatible Mono Development Tools In addition to the managed compilers, Mono ships with various development tools that are functionally equivalent to tools found in the Microsoft .NET SDK (some of which are identically named). Table B-3 enumerates the mappings between some of the commonly used Mono/Microsoft .NET utilities.

Table B-3. Mono Command-Line Tools and Their Microsoft .NET Counterparts

Mono Utility Microsoft .NET Utility Meaning in Life

al al.exe Manipulates assembly manifests and builds multifile assemblies (among other things).

gacutil gacutil.exe Interacts with the GAC.

mono when run with the -aot ngen.exe Performs a precompilation of an assembly’s option as a startup parameter CIL code. to the executing assembly

1570

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Table B-3. Mono Command-Line Tools and Their Microsoft .NET Counterparts (continued)

Mono Utility Microsoft .NET Utility Meaning in Life

wsdl wsdl.exe Generates client-side proxy code for XML web services.

disco disco.exe Discovers the URLs of XML web services located on a web server.

xsd xsd.exe Generates type definitions from an XSD schema file.

sn sn.exe Generates key data for a strongly named assembly.

monodis ildasm.exe The CIL disassembler

ilasm ilasm.exe The CIL assembler

xsp2 webdev.webserver.exe A testing and development ASP.NET web server

Mono-Specific Development Tools Mono also ships with development tools for which no direct Microsoft .NET Framework 3.5 SDK equivalents exist (see Table B-4).

Table B-4. Mono Tools That Have No Direct Microsoft .NET SDK Equivalent

Mono-Specific Development Tool Meaning in Life

monop The monop (mono print) utility displays the definition of a specified type using C# syntax (see the next section for a quick example). SQL# The Mono Project ships with a graphical front end (SQL#) that allows you to interact with relational databases using a variety of ADO.NET data providers. Glade 3 This tool is a visual development IDE for building GTK# graphical applications.

1571

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

■ Note You can load SQL# and Glade by using the Windows Start button and navigating to the Applications folder within the Mono installation. Be sure to do this because this illustrates definitively how rich the Mono platform has become.

Using monop You can use the monop utility (short for mono print) to display the C# definition of a given type within a specified assembly. As you might suspect, this tool can be quite helpful when you wish to view a method signature quickly, rather than digging through the formal documentation. As a quick test, try entering the following command at a Mono command prompt:

monop System.Object

You should see the definition of your good friend, System.Object:

[Serializable] public class Object {

public Object ();

public static bool Equals (object objA, object objB); public static bool ReferenceEquals (object objA, object objB); public virtual bool Equals (object obj); protected override void Finalize (); public virtual int GetHashCode (); public Type GetType (); protected object MemberwiseClone (); public virtual string ToString (); }

Building .NET Applications with Mono Now let’s look at Mono in action. You begin by building a code library named CoreLibDumper.dll. This assembly contains a single class type named CoreLibDumper that supports a static method named DumpTypeToFile(). The method takes a string parameter that represents the fully qualified name of any type within mscorlib.dll and obtains the related type information through the reflection API (see Chapter 15), dumping the class member signatures to a local file on the hard drive.

Building a Mono Code Library Create a new folder on your C: drive named MonoCode. Within this new folder, create a subfolder named CorLibDumper that contains the following C# file (named CorLibDumper.cs):

1572

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

// CorLibDumper.cs using System; using System.Reflection; using System.IO;

// Define assembly version. [assembly:AssemblyVersion("1.0.0.0")] namespace CorLibDumper { public class TypeDumper { public static bool DumpTypeToFile(string typeToDisplay) { // Attempt to load type into memory. Type theType = null; try { // Second parameter to GetType() controls if an // exception should be thrown if the type is not found. theType = Type.GetType(typeToDisplay, true); } catch { return false; }

// Create local *.txt file. using(StreamWriter sw = File.CreateText(string.Format("{0}.txt", theType.FullName))) { // Now dump type to file. sw.WriteLine("Type Name: {0}", theType.FullName); sw.WriteLine("Members:"); foreach(MemberInfo mi in theType.GetMembers()) sw.WriteLine("\t-> {0}", mi.ToString());

} return true; } } }

Like the Microsoft C# compiler, Mono’s C# compilers support the use of response files (see Chapter 2). While you could compile this file by specifying each required argument manually at the command line, you can instead create a new file named LibraryBuild.rsp (in the same location as CorLibDumper.cs) that contains the following command set:

/target:library /out:CorLibDumper.dll CorLibDumper.cs

You can now compile your library at the command line, as follows: mcs @LibraryBuild.rsp

1573

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

This approach is functionally equivalent to the following (more verbose) command set:

mcs /target:library /out:CorLibDumper.dll CorLibDumper.cs

Assigning CoreLibDumper.dll a Strong Name Mono supports the notion of deploying strongly named assemblies (see Chapter 15) to the Mono GAC. To generate the necessary public/private key data, Mono provides the sn command-line utility, which functions more or less identically to Microsoft’s tool of the same name. For example, the following command generates a new *.snk file (specify the -? option to view all possible commands):

sn -k myTestKeyPair.snk

You can tell the C# compiler to use this key data to assign a strong name to CorLibDumper.dll by updating your LibraryBuild.rsp file with the following additional command:

/target:library /out:CorLibDumper.dll /keyfile:myTestKeyPair.snk CorLibDumper.cs

Now recompile your assembly:

mcs @LibraryBuild.rsp

Viewing the Updated Manifest with monodis Before you deploy the assembly to the Mono GAC, you should familiarize yourself with the monodis command-line tool, which is the functional equivalent of Microsoft’s ildasm.exe (without the GUI front end). Using monodis, you can view the CIL code, manifest, and type metadata for a specified assembly. In this case, you want to view the core details of your (now strongly named) assembly using the --assembly flag. Figure B-5 shows the result of the following command set:

monodis --assembly CorLibDumper.dll

1574

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Figure B-5. Viewing the CIL Code, Metadata, and Manifest of an Assembly with monodis

The assembly’s manifest now exposes the public key value defined in myTestKeyPair.snk.

Installing Assemblies into the Mono GAC So far you have provided CorLibDumper.dll with a strong name; you can install it into the Mono GAC using gacutil. Like Microsoft’s tool of the same name, Mono’s gacutil supports options to install, uninstall, and list the current assemblies installed under C:\Program Files\Mono- \lib\mono\gac. The following command deploys CorLibDumper.dll to the GAC and sets it up as a shared assembly on the machine: gacutil -i CorLibDumper.dll

■ Note Be sure to use a Mono command prompt to install this binary to the Mono GAC! If you use the Microsoft gacutil.exe program, you’ll install CorLibDumper.dll into the Microsoft GAC!

After you run the command, opening the \gac directory should reveal a new folder named CorLibDumper (see Figure B-6). This folder defines a subdirectory that follows the same naming conventions as Microsoft’s GAC (versionOfAssembly__publicKeyToken).

1575

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Figure B-6. Deploying Your Code Library to the Mono GAC

■ Note Supplying the -l option to gacutil lists out each assembly in the Mono GAC.

Building a Console Application in Mono Your first Mono client will be a simple, console-based application named ConsoleClientApp.exe. Create a new file in your C:\MonoCode\CorLibDumper folder, ConsoleClientApp.cs, that contains the following Program class definition:

// This client app makes use of the CorLibDumper.dll // to dump type information to a file. using System; using CorLibDumper;

namespace ConsoleClientApp { public class Program { public static void Main(string[] args) { Console.WriteLine("***** The Type Dumper App *****\n");

// Ask user for name of type. string typeName = ""; Console.Write("Please enter type name: "); typeName = Console.ReadLine();

// Now send it to the helper library. if(TypeDumper.DumpTypeToFile(typeName))

1576

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Console.WriteLine("Data saved into {0}.txt", typeName); else Console.WriteLine("Error! Can't find that type..."); } } }

Notice that the Main() method prompts the user for a fully qualified type name. The TypeDumper.DumpTypeToFile() method uses the user-entered name to dump the type’s members to a local file. Next, create a ClientBuild.rsp file for this client application and reference CorLibDumper.dll:

/target:exe /out:ConsoleClientApp.exe /reference:CorLibDumper.dll ConsoleClientApp.cs

Now, use a Mono command prompt to compile the using mcs, as shown here: mcs @ClientBuild.rsp

Loading Your Client Application in the Mono Runtime At this point, you can load ConsoleClientApp.exe into the Mono runtime engine by specifying the name of the executable (with the *.exe file extension) as an argument to Mono: mono ConsoleClientApp.exe

As a test, enter System.Threading.Thread at the prompt and press the Enter key. You will now find a new file named System.Threading.Thread.txt containing the type’s metadata definition (see Figure B-7).

Figure B-7. The Results of Running Your Client Application

1577

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Before moving on to a Windows Forms–based client, try the following experiment. Use Windows Explorer to rename the CorLibDumper.dll assembly from the folder containing the client application to DontUseCorLibDumper.dll. You should still be able to run the client application successfully because the only reason you needed access to this assembly when building the client was to update the client manifest. At runtime, the Mono runtime will load the version of CorLibDumper.dll you deployed to the Mono GAC. However, if you open Windows Explorer and attempt to run your client application by double- clicking ConsoleClientApp.exe, you might be surprised to find a FileNotFoundException is thrown. At first glance, you might assume this is due to the fact that you renamed CorLibDumper.dll from the location of the client application. However, the true reason for the error is that you just loaded ConsoleClientApp.exe into the Microsoft CLR! To run an application under Mono, you must pass it into the Mono runtime through Mono. If you do not, you will be loading your assembly into the Microsoft CLR, which assumes all shared assemblies are installed into the Microsoft GAC located in the <%windir%>\Assembly directory.

■ Note If you double-click your executable using Windows Explorer, you will load your assembly into the Microsoft CLR, not the Mono runtime!

Building a Windows Forms Client Program Before continuing, be sure to rename DontUseCorLibDumper.dll back to CorLibDumper.dll, so you can compile the next example. Next, create a new C# file named WinFormsClientApp.cs and save it in the same location as your current project files. This file defines two class types:

using System; using System.Windows.Forms; using CorLibDumper; using System.Drawing;

namespace WinFormsClientApp { // Application object. public static class Program { public static void Main(string[] args) { Application.Run(new MainWindow()); } }

// Our simple Window. public class MainWindow : Form { private Button btnDumpToFile = new Button(); private TextBox txtTypeName = new TextBox();

1578

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

public MainWindow() { // Config the UI. ConfigControls(); }

private void ConfigControls() { // Configure the Form. Text = "My Mono Win Forms App!"; ClientSize = new System.Drawing.Size(366, 90); StartPosition = FormStartPosition.CenterScreen; AcceptButton = btnDumpToFile;

// Configure the Button. btnDumpToFile.Text = "Dump"; btnDumpToFile.Location = new System.Drawing.Point(13, 40);

// Handle click event anonymously. btnDumpToFile.Click += delegate { if(TypeDumper.DumpTypeToFile(txtTypeName.Text)) MessageBox.Show(string.Format( "Data saved into {0}.txt", txtTypeName.Text)); else MessageBox.Show("Error! Can't find that type..."); }; Controls.Add(btnDumpToFile);

// Configure the TextBox. txtTypeName.Location = new System.Drawing.Point(13, 13); txtTypeName.Size = new System.Drawing.Size(341, 20); Controls.Add(txtTypeName); } } }

To compile this Windows Forms application using a response file, create a file named WinFormsClientApp.rsp, and add the following commands:

/target:winexe /out:WinFormsClientApp.exe /:CorLibDumper.dll /r:System.Windows.Forms.dll /r:System.Drawing.dll WinFormsClientApp.cs

Now make sure this file is saved in the same folder as your example code, and supply this response file as an argument to mcs (using the @ token):

1579

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

msc @WinFormsClientApp.rsp Finally, run your Windows Forms application using Mono:

mono WinFormsClientApp.exe

Figure B-8 shows a possible test run.

Figure B-8. A Windows Forms Application Built Using Mono

Executing Your Windows Forms Application Under Linux So far, this appendix has shown you how to create a few assemblies that you could also have compiled using the Microsoft .NET Framework 4.0 SDK. However, the importance of Mono becomes clear when you view Figure B-9, which shows the same exact Windows Forms application running under SuSe Linux. Notice how the Windows Forms application has taken on the correct look and feel of my current desktop theme.

Figure B-9. Executing the Windows Forms Application Under SuSe Linux

■ Source Code You can find the CorLibDumper project under the Appendix B subdirectory.

The preceding examples shows how you can compile and execute the same exact C# code shown during this appendix on Linux (or any OS supported by Mono) using the same Mono development tools. In fact, you can deploy or recompile any of the assemblies created in this text that do not use .NET 4.0 programming constructs to a new Mono-aware OS and run them directly using the Mono runtime utility. Because all assemblies contain platform-agonistic CIL code, you do not need to recompile the applications whatsoever.

1580

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Who is Using Mono? In this short appendix, I’ve tried to capture the promise of the Mono platform in a few simple examples. Granted, if you intend only to build .NET programs for the Windows family of operating systems, you might not have encountered companies or individuals who actively use Mono. Regardless, Mono is alive and well in the programming community for Mac OS X, Linux, and Windows. For example, navigate to the /Software section of the Mono website: http://mono-project.com/Software

At this location, you can find a long-running list of commercial products built using Mono, including development tools, server products, video games (including games for the Nintendo Wii and iPhone), and medical point-of-care systems. If you take a few moments to click the provided links, you will quickly find that Mono is completely equipped to build enterprise-level, real-world .NET software that is truly cross-platform. Suggestions for Further Study If you have followed along with the materials presented in this book, you already know a great deal about Mono, given that it is an ECMA-compatible implementation of the CLI. If you want to learn more about Mono’s particulars, the best place to begin is with the official Mono website (www.mono- project.com). Specifically, you should examine the page at www.mono-project.com/Use, which serves an entry point to a number of important topics, including database access using ADO.NET, web development using ASP.NET, and so on. I have also authored some Mono-centric articles for the DevX website (www.devx.com) that you might find interesting: • “Mono IDEs: Going Beyond the Command Line”: This article examines many Mono-aware IDEs. • “Building Robust UIs in Mono with Gtk#”: This article examines building desktop applications using the GTK# toolkit as an alternative to Windows Forms. Finally, you should familiarize yourself with Mono’s documentation website (www.go- mono.com/docs). Here you will find documentation on the Mono base class libraries, development tools, and other topics (see Figure B-10).

1581

APPENDIX B ■ PLATFORM-INDEPENDENT .NET DEVELOPMENT WITH MONO

Figure B-10. The Online Mono Documentation

■ Note The website with Mono’s online documentation is community supported; therefore, don’t be too surprised if you find some incomplete documentation links! Given that Mono is an ECMA-compatible distribution of Microsoft .NET, you might prefer to use the feature-rich MSDN online documentation when exploring Mono.

Summary The point of this appendix was to provide an introduction to the cross-platform nature of the C# programming language and the .NET platform when using the Mono framework. You have seen how Mono ships with a number of command-line tools that allow you to build a wide variety of .NET assemblies, including strongly named assemblies deployed to the GAC, Windows Forms applications, and .NET code libraries. You’ve also learned that Mono is not fully compatible with the .NET 3.5 or .NET 4.0 programming APIs (WPF, WCF, WF, or LINQ) or the C# 2010 language features. Efforts are underway (through the Olive project) to bring these aspects of the Microsoft .NET platform to Mono. In any case, if you need to build .NET applications that can execute under a variety of operating systems, the Mono project is a wonderful choice for doing so.

1582

■ ■ ■

Index

overloadability, 445 ■SPECIAL CHARACTERS overloading, 453 * pointer-centric operator, 479 AND NUMERICS *= operator, 445 - (dash) symbol, 44 . (dot) prefix, 655 - operator, 445, 452 "." notation, 779 -- operator /? flag, 565 CIL representation, 452 / operator, 445 overloadability, 445 /= operator, 445 overloading, 449 /addmodule flag, 551 -? option, 663 /checked flag, 110, 111 - pointer-centric operator, 479 /clrheader flag, 535 -- pointer-centric operator, 479 /connectionstring: option, 962 - unary operator, 445 /debug flag, 663 ! operator, 121 /dll flag, 663 != operator, 102, 120, 163, 445, 450, 452 /exe flag, 664 != pointer-centric operator, 479 /FalseString property, 93 # character, 47 /GODMODE value, 1139 % operator, 431, 445 /headers flag, 534 <%@Assembly%> directives, 1398, 1402, /i option, 565 1403 /key flag, 664 %= operator, 445 /keyf option, 575 %ERRORLEVEL% variable, 76 /keyfile option, 562 %FlowDocument> element, 1228 /l option, 565 & (ampersand) suffix, 23, 677 /language: option, 962 & operator, 445, 482 /ldl option, 576 & pointer-centric operator, 479 /main option, 74 & symbol, 1094 /mode:FullGeneration option, 961 && operator, 121, 506 /noconfig option, 48 &= operator, 445 /nostdlib option, 45 * operator, 482 /out flag, 44, 575, 1569 CIL representation, 452 /out option, C# compiler, 44, 551

1583

INDEX ■

/output flag, 664 | operator, 445 /out:TestApp.exe flag, 48 || operator, 121 /pluralize option, 962 |= operator, 445 /project: option, 961 ~ (tilde symbol), 303 /r flag, 45, 46, 48 ~ operator, 445 /r option, 49 ~/ prefix, 1446 /reference flag, 45, 48, 1569 + (plus) operator, 23, 99, 100, 1094 /reference option, 57 + (plus token), 589 /t flag, 44 + binary operator, 445, 447 /target flag, 44, 550, 1514, 1569 + operator, 452 /target:exe option, 44, 1514 + pointer-centric operator, 479 /target:library option, C# compiler, 44 + symbol, 99 /target:module option, C# compiler, 44 + unary operator, 445 /target:winexe option, 44, 1149, 1514 ++ operator /t:exe flag, 44 CIL representation, 452 /t:library option, 551 overloadability, 445 /u option, 565 overloading, 449 /unsafe flag, 480 ++ pointer-centric operator, 479 ? operator, 137 += and -+ operator overloading, 448 ?? operator, nullable types, 164—165 += operator, 408, 409 ? suffix, 162, 163 CIL representation, 452 ? token, 115 overloadability, 445 [ ] (index operator), accessing items from += syntax, 423, 428 arrays, 439 < operator, 120, 452 \" escape character, 100 < pointer-centric operator, 479 \\ escape character, 100 <%@Page%> directive, 1401, 1402, 1403, \" escape character, 101 1409, 1411, 1424, 1443, 1449, 1469, \\ escape character, 101 1477 \a escape character, 100 <<= operator, 445 \gac directory, 1575 << operator, 445 \Images folder, 1287 <= operator, 120, 445, 452 \n escape character, 101 <= pointer-centric operator, 479 \r escape character, 101 < operator, 445 \SQLEXPRESS token, 854 -= operator, 422, 445, 452 \t escape character, 101 =< operator, 437 ^ operator, 445 == operator, 120 ^= operator, 445 CIL representation, 452 __VIEWSTATE field, 1392, 1476, 1477, overloadability, 445 1478, 1479 overloading, 450 __?VIEWSTATE form field, 1478 == operetor, 102 _contentLoaded member variable, 1150, == pointer-centric operator, 479 1151 => pointer-centric operator, 479 _Default class, 1409, 1410 >, 445 _Exception interface, 262 -> operator, 484 { and } tokens, 210 >= operator, 120, 452

1584

INDEX ■

>> operator, 445 AcceptAllChanges( ) method, 959 >>= operator, 445 AcceptButton property, 1529, 1541 > operator, 120 AcceptChanges( ) method, 888, 889, 893, > pointer-centric operator, 479 895, 896 -> pointer-centric operator, 479 access modifiers, 303 0 (integer), 1335 default, 193 0x prefix, 675 and nested types, 194 0X58 opcode, 656 overview, 192 0X59 opcode, 656 accessing profile data programmatically, 0X73 opcode, 656 1505—1507 2D arrays, 443 accessor method, 194, 195, 196, 198, 200, 2D geometric objects, 1246 206 2D graphical data, 1119, 1254 Accessories menu option, 43 2D graphics, 1120 accessors and mutators, for encapsulation 2D vector images, 1254, 1271 of classes, 195—197 3D animation, 1118 Account property, 1065 3D functionality, 1118 ACID (Atomic, Consistent, Isolated, 3D graphical data, 1119 Durable), 878 3D graphics, 1120 action attribute, 1384, 1390, 1417 100% C# code, 1139 Action<> delegate, 771 100% code approach, 1078 Action delegate, 763, 765, 766 100% XAML free, 1144, 1145 Activate( ) method, 1530 Activated event, 1531, 1532, 1533 Activator.CreateInstance( ) method, 601, ■A 602, 710 (ASP).NET Web ABCs. See addresses, bindings, and Application, 1412, 1413, 1414 contracts Active Server Pages (ASP).NET Web page, Abort( ) method, 742 1412, 1414 About boxes, 1542, 1543 Active Server Pages (ASP).NET Web Site, AboutToBlow event, 420, 428, 429, 430 1412, 1413 aboutToBlowCounter integer, 429 (ATL), 6 abstract attribute, 669 ActiveMDIChild property, 1529 abstract classes, 240, 244 ActiveX Data Objects (ADO), 1394, 1420 abstract FileSystemInfo base class, 777— ActiveX UI controls, 1522 778 activities, WF 4.0, 1088—1093 abstract keyword, 188, 240, 241, 244 collection, 1092—1093 abstract members, 191, 241, 321, 695 connecting in flowchart workflow, 1094 abstract methods, 244 control flow, 1089 abstract stream class, 792—794 error handling, 1092—1093 abstraction, 837 flowchart, 1089—1090 Accelerate( ) method, 265, 266, 267, 274, messaging, 1090—1091 277, 405, 406, 420, 425 primitives, 1091 AccelerationRatio property, Timeline class, runtime, 1091 1305 transaction, 1091—1092

1585

INDEX ■

Activity Library project, 1103 Add State Group button, 1367 element, 1082, 1104 Add Sticky Note button, 1234 node, 1081 Add TabItem option, 1213 Activity1.xaml file, 1103 Add This Car button, 1492 ActualHeight property, Add Transition button, 1369 FrameworkElement type, 1133 Add UserControl menu option, 1331 ActualWidth property, FrameworkElement Add Web Reference option, 1018 type, 1133 Add Windows Form menu option, 1543 element, 1448 Add Windows Forms menu option, 1538 adaptive rendering, 1389 add_ prefix, 421 Add another item area, 1218 add_AboutToBlow( ) method, 421 Add another item button, 1217, 1230 add_Exploded( ) method, 421 Add another item dropdown list, 1218 elements, 578 Add button, 224, 226, 719 AddChild( ) method, 1138 Add class menu item, 195 AddComplete( ) method, 736, 737, 738, 739 Add Content Page menu option, 1448, AddDefaultEndpoints( ) method, 1040, 1455 1063 Add Existing Item menu option, 226, 273, AddInventoryRow( ) method, 934 325, 343, 984, 986, 1242, 1448 AddMemoryPressure( ) method, Add Existing Item option, 277, 1358 System.GC class, 298 Add Function Import menu option, 980 AddObject( ) method, 959, 974 Add Installer option, 1064 .addon directive, 421 Add Keyframe button, 1362 AddOne( ) method, 757 add mnemonic, 656 AddParams parameter, 747 Add New Case link, 1108 AddPerson( ) method, 368 Add New Diagram menu option, 846 AddRange( ) method, 1515 Add New Item dialog box, 1298 AddRecord( ) method, 943 Add New Item menu option, 224, 325, 531, AddRecords( ) method, 951 938, 962, 1037, 1109, 1240, 1445, AddRef( ) method, 292 1448 Add/Remove WizardSteps link, 1455 Add New Item menu selection, 1442 address attribute, 1039 Add New Stored Procedure option, 843 address element, 1037 Add New Table option, 841 Address group, 1507 add opcode, 678 addresses, bindings, and contracts (ABCs) Add Project Data Source link, 927 addresses, 1031—1032 Add Reference dialog box, 57, 492, 541, bindings 546, 547, 567, 714, 715, 716, 1105 HTTP-based, 1029—1030 Add Reference menu option, 57, 96, 541, MSMQ-based, 1031 547, 1072, 1364, 1513 overview, 1028 Add References dialog box, 53, 552, 716 TCP-based, 1030 Add Service Reference dialog box, 1067, contracts, 1027 1075 establishing within App.config files, Add Service Reference menu option, 1043, 1037 1047 specifying in code, 1062—1063 Add State button, 1367, 1368

1586

INDEX ■

AddServiceEndpoint( ) method, 1040, data provider factory model 1051, 1063 element, 852— AddToCollection activity, WF 4.0, 1092 853 AddWithThreads application, 747 complete data provider factory AddWithThreads project, 749 example, 848—851 Administrative Tools folder, 1066, 1500 overview, 847 ADO (ActiveX Data Objects), 1394, 1420 potential drawback with provide ADO.NET factory model, 851—852 abstracting data providers using data providers interfaces, 837—840 Microsoft-supplied, 829—830 additional namespaces, 831—832 overview, 827 building reusable data access library system.Data.OracleClient.dll, 830— adding connection logic, 863 831 adding deletion logic, 865 third-party, obtaining, 831 adding insertion logic, 863—864 data readers, 859—861 adding selection logic, 866 database transactions adding update logic, 865 adding CreditRisks table to AutoLot executing stored procedure, 869— database, 879—880 871 adding transaction method to overview, 861 InventoryDAL, 880—882 parameterized command objects, key members of transaction object, 867—869 878—879 connected layer of overview, 877 command objects, 858 testing, 882—883 connection objects, 854—856 high-level definition of, 825—827 ConnectionStringBuilder objects, overview, 825 856—857 System.Data namespace, types of overview, 853 IDataReader and IDataRecord creating AutoLot database interfaces, 836 authoring GetPetName( ) stored IDbCommand interface, 834 procedure, 843 IDbConnection interface, 833 creating customers and orders IDbDataAdapter and IDataAdapter tables, 844 interfaces, 835 creating inventory table, 840—842 IDbDataParameter and visually creating table relationships, IDataParameter interfaces, 834— 846—847 835 creating console UI-based front end IDbTransaction interface, 834 DeleteCar( ) method, 875 overview, 832 InsertNewCar( ) method, 875—876 AdoNetTransaction application, 882 ListInventory( ) method, 874 AdoNetTransaction project, 883 LookUpPetName( ) method, 876 AdornerDecorator, 1344 Main( ) method, 872 adornments, 22 overview, 871 AdRotator control, 1439, 1444, 1447, 1448, ShowInstructions( ) method, 873 1449 UpdateCarPetName( ) method, 876 AdRotator widget, 1447—1448

1587

INDEX ■

Ads. file, 1447, 1448 animated styles, WPF, 1318 Advanced button, 110, 1067 Animation classes, 1304, 1305, 1308 Advanced Properties button, 1301 animation editor mode, 1360 Advanced properties square, 1297 Animation elements, 1310 Advanced Property options, 1236 Animation objects, 1308, 1309 AdvertisementFile property, 1447, 1448 animation services, WPF Age property, 200, 379, 384 Animation class types, 1304—1305 Aggregate( ) method, 500 authoring animation in C# code, 1306— aggregation, 232 1307 AirVehicles assembly, 550 authoring animation in XAML AirVehicles namespace, 550 discrete key frames, 1311—1312 airvehicles.dll file, 551—552 event triggers, 1310—1311 al utility, Mono, 1570 overview, 1309 alert( ) method, 1389 storyboards, 1310 al.exe utility, 575, 1570 looping animation, 1308—1309 aliases, resolving name clashes with, 528— overview, 1303 530 pacing of animation, controlling, 1307— AllKeys property, HttpApplicationState 1308 type, 1484 From property, 1305 allowAnonymous attribute, 1504 By property, 1305 AllowDBNull property, 890, 891 To property, 1305 AllowMultiple property, 612 reversing animation, 1308—1309 allSongs object, 314 Timeline Base class, 1305 AllTracks class, 313, 315 Animation token, 1304 AllTracks object, 315, 316 animation tools, 1304 AllTracks variable, 314, 315 animations alpha, red, green and blue (ARGB), 1259 authoring, 1304 Alt key shortcut, 1197, 1516 building, 1304 Alt property, 1537 defining with Expression Blend, 1359— Alt+F shortcut, 1516 1363 Alt+X shortcut, 1516 key , 1304 ALTER PROCEDURE statement, 843 linear interpolation, 1304 altering configuration files using path-based, 1304 SvcConfigEditor.exe, 1059—1061 programmatically starting storyboard, AlternateText text, 1448 1363—1364 AlternatingRowBackground property, 1243 annotations, Documents tab, 1232—1234 AlternationCount property, 1243 AnnotationService class, 1234 ampersand (&) suffix, 23, 677 AnnotationService object, 1234 Ancestors( ) method, 1000 AnnotationStore, 1234 Anchor property, 1526 anonymous methods, 9, 427—430, 763 and opcode, 678 anonymous profiles, 1507 angle brackets, 620 anonymous types, 493 Angle property, 1307 containing anonymous types, 478 Animatable, 1272 equality for, 476—478 Animate parameter, 1305 internal representation of, 474—475

1588

INDEX ■

overview, 473 creating ToString( ) and GetHashCode( ), 476 loading assemblies into custom AnonymousMethods project, 430 application domains, 645 AnonymousTypes project, 474, 479 overview, 643—644 Any( ) method, 1107 programmatically unloading API (application programming interface), AppDomains, 646—648 1013, 1014, 1015, 1016, 1017, 1391— default, interacting with, 640—643 1395 overview, 637—639 API (CardSpace application programming System.AppDomain class, 638—639 interface), 1023, 1030 AppDomains (application domains), API (C/Windows application programming defined, 625 interface), 4 Append member, FileMode enumeration, API (Simple application programming 787 interface)XML ( for Extensible AppendText( ) method, FileInfo class, 785, Markup Language)SAX (), 993 789 API (Windows Application Programming AppExit( ) method, 1137 Interface), 260, 285, 286, 729 application cache API features data caching, 1489—1491 1.0-1.1, 1392—1393 modifying *.aspx file, 1491—1493 2.0, 1393—1394 overview, 1488 3.5 (and .NET 3.5 SP1), 1394 Application class, 1138, 1139, 1144, 1145 4.0, 1394—1395 Application.Windows collection, overview, 1391 enumerating, 1130 App_Browsers subdirectory, 1414 constructing, 1129—1130 App_Code directory, 1415 overview, 1128 App_Code folder, 1072, 1414, 1415 Application App_Code subdirectory, 1414 (COM) object, 1483 App_Data folder, 1415, 1440, 1503, 1506, application data, modifying, 1486—1487 1508 Application -derived class, 1137 App_Data subdirectory, 1414, 1503 application directory, 553 App_GlobalResources subdirectory, 1414 application domains (AppDomains), App_LocalResources subdirectory, 1414 defined, 625 App_Theme folder, 1466, 1469 application error code, C# programming, App_Themes folder, 1415, 1465, 1466, 1467 76—77 App_Themes subdirectory, 1414 Application markup, 1350 App_WebReferences subdirectory, 1414 application object, 73, 74, 1129 App.config file, 557, 558, 849, 852, 857, 871, application programming interface (API), 932, 984, 986, 1037 1013, 1014, 1015, 1016, 1017, 1391— AppConfigReaderApp application, 578, 579 1395 AppDomain shutdown, 304 Application property, 1416, 1482, 1483, AppDomain.CreateDomain( ) method, 643 1485 AppDomain.DefineDynamicAssembly( ) application resources, embedding, 1289— method, 693 1291 AppDomain.Load( ) method, 645 application roots, and object lifetime, 294— AppDomains (application domains) 295

1589

INDEX ■

application shutdown, handling, 1488 implementing Tools menu application state functionality, 1555—1556 handling web application shutdown, main menu system, 1552—1553 1488 populating controls collection, maintaining application-level state 1515—1517 data, 1484—1486 ShapeData type, 1553 modifying application data, 1486—1487 ShapePickerDialog type, 1553—1555 overview, 1483 System.EventArgs and Application tab, 74, 531, 565, 571, 919, System.EventHandler, 1517—1518 1144, 1514 client, building, 1046—1050 Application type, 1121, 1522 composition of, 1025—1027 application variable, web-based, 1124 web, 1380—1382 Application_End( ) method, 1481, 1488 Applications folder, 1572 Application_Error( ) event, 1481, 1482 Applications tab, 984 Application_Start( ) event, 1481, 1485, Application.Windows collection, 1489, 1490 enumerating, 1130 element, 1156 Application.Windows property, 1138 ApplicationCommands class, WPF, 1201 apply attribute, 575 ApplicationCommands object, 1205 Apply Resource option, 1297 ApplicationCommands.Help command, ApplyingAttributes application, 606 1203 element, 578, 839, 849, 852, Application.Current property, 1140 1427 element, 1149 AppStartUp( ) method, 1137 Application-derived class, 1130, 1147, 1153 AppState project, 1485 Application-derived type, 1130, 1153, 1166 App.xaml file, 1297, 1303, 1313, 1323, 1350, ApplicationException class, 276 1354 Application.Exit( ) method, 1517 arbitrary actions, connecting WPF application-level exceptions commands to, 1203—1204 (System.ApplicationException), ARGB (alpha, red, green and blue), 1259 273—276 Args property, 1140 application-level resources, 1296—1297 ArgumentException exception, 631 application-level state data, maintaining, ArgumentOutOfRangeException class, 1484—1486 260, 272, 277, 278, 279 ApplicationPath property, 1418 arguments Application.Resources scope, 1297, 1299 array as, 142 Application.Run( ) method, 1514, 1515, command-line, 1139 1522, 1531 optional, 180—181 applications workflow building, 1513—1518, 1551—1560 defining, 1105—1106 adding infrastructure to defining using workflow designer, MainWindow type, 1555 1084—1086 capturing and rendering graphical passing to workflows using output, 1557 WorkflowInvoker class, 1084 implementing serialization logic, retrieving output, 1113—1114 1558—1560 Arguments button, 1084, 1094

1590

INDEX ■

arithmetic operations, 756 AsParallel( ) method, 771 Array class, 519 AsParallel( )method, 772 Array object, 513 AsParallel( ) method, 772 Array of [T] option, 1098 control, 1392 array variable, 137 scope, 1448, 1449 ArrayList class, 362, 365, 366, 367, 371, component, 1479 1449 ArrayList.Add( ) method, 366 definition, ArrayOfObjects( ) method, 139, 140 1443 Array.Reverse( ) method, 144 element, 1443 arrays tag, 1443, 1448 as arguments, 142 declarations, 1478 defined, 137 ASP.NET Development web server, 1393 generating documents from, 1004—1005 ASP.NET. Java web applications, 1475 implicitly typed local, 139 ASP.NET master pages, 1442—1448 initialization syntax, 138 ASP.NET session state server, 1500, 1502 of interface types, 334 ASP.NET state management techniques multidimensional, 140—141 application cache of objects, 139—140 data caching, 1489—1491 overview, 137 modifying *.aspx file, 1491—1493 primitive, applying LINQ queries to, overview, 1488 496—503 application/session distinction as return values, 142 handling web application System.Array class, 142—144 shutdown, 1488 Array.Sort( ) method, 144 maintaining application-level state as keyword, 249, 307, 330 data, 1484—1486 ASC (ascending), 910 modifying application data, 1486— ascending (ASC), 910 1487 ascending operator, 509, 514 overview, 1483 AsDataView( ) method, 949 cookies AsEnumerable( ) method, 947, 948 creating, 1498—1499 AskForBonus( ) method, 146 overview, 1497 AsmReader class, 697 reading incoming data, 1499 *.asmx file, 1017 Global.asax file ASP (Active Server Pages).NET Web global last-chance exception event Application, 1412, 1413, 1414 handler, 1481—1482 ASP (Active Server Pages).NET Web page, HttpApplication base class, 1482 1412, 1414 overview, 1479 ASP (Active Server Pages).NET Web Site, maintaining session data, 1493—1497 1412, 1413 overview, 1473 ASP applications, 1475 Profile API *.asp file, 1476 accessing profile data asp\: tag prefix, 1403 programmatically, 1505—1507 definitions, 1477 ASPNETDB.mdf database, 1503— tag, 1397 1504

1591

INDEX ■

defining user profiles within client-side scripting, 1388—1390 Web.config, 1504—1505 HTTP grouping profile data and persisting request/response cycle, 1380 custom objects, 1507—1509 stateless protocols, 1380 overview, 1502 Hypertext Markup Language (HTML) role of elements building forms, 1386—1387 storing session data in ASP.NET document structure, 1383—1384 session state servers, 1500—1501 forms, 1384 storing session data in dedicated overview, 1382 databases, 1502 Visual Studio 2010 designer tools, view state 1384—1386 adding custom data, 1478—1479 incoming HTTP requests demonstrating, 1477—1478 access to incoming form data, 1419— overview, 1476 1420 ASP.NET themes IsPostBack property, 1420 *.skin files, 1466—1468 obtaining brower statistics, 1419 applying at page level, 1469 overview, 1417 applying sitewide, 1468 inheritance chain of Page type, 1416 assigning programmatically, 1469—1471 life cycle of overview, 1465 AutoEventWireup attribute, 1424— SkinID property, 1469 1425 ASP.NET web controls Error event, 1425—1426 AutoPostBack property, 1431 overview, 1423 categories of outgoing HTTP response documentation, 1441 emitting HTML content, 1422 overview, 1438 overview, 1421 System.Web.UI.HtmlControls, redirecting users, 1422—1423 1440—1441 posting back to Web servers, 1390—1391 control and WebControl base classes single file Web pages dynamically adding and removing adding data access logic, 1397—1401 controls, 1435—1436 ASP.NET control declarations, 1403— enumerating contained controls, 1404 1432—1435 ASP.NET directives, 1401—1403 interacting with dynamically created compilation cycle for single-file controls, 1436—1437 pages, 1405—1406 WebControl base class, 1437—1438 designing UI, 1396—1397 overview, 1429 overview, 1395 server-side event handling, 1430 referencing AutoLotDAL.dll, 1396 ASP.NET Web pages, building "script" block, 1403 API features using code files 1.0-1.1, 1392—1393 compilation cycle for multifile 2.0, 1393—1394 pages, 1410 3.5 (and .NET 3.5 SP1), 1394 debugging and tracing ASP.NET 4.0, 1394, 1395 pages, 1410—1411 overview, 1391 overview, 1406

1592

INDEX ■

referencing AutoLotDAL.dll overview, 33 assembly, 1409 viewing assembly metadata, 35 updating code file, 1409—1410 viewing Common Intermediate Web applications and servers Language (CIL) code, 34 ASP.NET development web server, viewing type metadata, 34 1382 exploring using Reflector, 35—36 IIS virtual directories, 1381 external, 536, 1081 overview, 1380 friend, 545 Web site directory structure interop, 714, 717 App_Code folder, 1415 interoperability, 714, 716 overview, 1413 loaded referencing assemblies, 1414—1415 enumerating, 641—642 Web sites and Web applications, 1412— receiving assembly load 1413 notifications, 643 Web.config files, 1427—1428 loading, 553, 645 ASP.NET template, Visual localized, 598 Studio, 1017 metadata, 17—18 aspnet_compiler.exe tool, 1410, 1427 multi-file, 14 aspnet_regsql.exe, 1503 production-ready, 1562 aspnet_state.exe, 1500, 1501 referencing external, 32, 1414—1415 aspnet_wp.exe, 1500 with csc.exe, 45—46 AspNetCarsSite application, 1456 with Visual Studio 2010, 57 AspNetCarsSite project, 1442 resource-only, defining, 1300—1301 AspNetCarsSite website, 1457 shared, 598—600 ASPNETDB.mdf database, 1503—1504, single-file, 14 1506, 1507, 1508, 1509 workflow, importing, 1105 tag, 1429 WPF .aspx files, 1479 Application class, 1128—1130 *.aspx files, modifying, 1491—1493 overview, 1126—1127 *.aspx page, 1495, 1499 Window class, 1130—1135 .aspx pages, 1477, 1479 element, 1414 assemblies, 12—19. See also .NET assembly, 13 assemblies Assembly class, 587, 596 CLS compliant, 612 .assembly directive, 662, 666, 667 and Common Intermediate Language Assembly directory, 559 (CIL) .assembly extern block, 542 benefits of, 16—17 .assembly extern directives, 19, 660, 667 compiling to platform-specific .assembly extern tokens, 542, 554, 660 instructions, 17 --assembly flag, 1574 overview, 14—15 Assembly Information button, 543, 565, documenting 571, 919, 984 defining assembly, 585 assembly , 575 referenced assemblies, 585 assembly manifest, 18—19 dynamically loading, 596—598 assembly metadata, 35, 536, 586 exploring using ildasm.exe Assembly reference, 596

1593

INDEX ■

Assembly table, 585 assigning themes programmatically, 1469— assembly token, 585, 1159 1471 Assembly type, 596 Associations folder, 983 Assembly Version number, 571 AsyncCallback delegate, 736—738, 1069 [assembly:] tag, 612 AsyncCallback object, 736 element, 555 AsyncCallback parameter, 399 AssemblyBuilder member, 689 AsyncCallbackDelegate project, 739, 747 AssemblyBuilder type, 692, 693 AsyncDelegate application, 733 AssemblyCompanyAttribute attribute, 613 AsyncDelegate project, 735 AssemblyCopyrightAttribute attribute, 613 AsyncDelegate property, 738 [AssemblyCulture] attribute, 562 asynchronous delegate pattern, .NET, 1086 AssemblyCultureAttribute attribute, 614 asynchronous delegates, 762 AssemblyDescriptionAttribute attribute, asynchronous method invocations, 22, 614 727, 731, 739 element, 573—577 asynchronously method, 398 AssemblyInfo.cs file, 543, 544, 562, 563, AsyncPattern property, 1035 613, 658 AsyncResult class, 738, 774 [AssemblyKeyFile] attribute, 560, 562 AsyncState property, 739 AssemblyKeyFileAttribute attribute, 614 AsyncWaitHandle property, IAsyncResult assembly-level (and module-level) interface, 735 attributes, 612—613 ATL (Active Template Library), 6 AssemblyLoad event, AppDomain class, Atomic, Consistent, Isolated, Durable 640 (ACID), 878 Assembly.Load( ) method, 597, 598, 599, atomic operations, 729 602, 1415 attached properties, 1162, 1326 AssemblyLoadEventHandler delegate, 643 Attribute code snippet, Visual Studio 2010, Assembly.LoadFrom( ) method, 598, 602 610 AssemblyName class, System.Reflection Attribute suffix, 607 Namespace, 587 Attribute token, 607 AssemblyName type, 599, 693 AttributedCarLibrary assembly, 611, 614, AssemblyProductAttribute attribute, 614 615 AssemblyRef #n tokens, 585 AttributedCarLibrary project, 609 AssemblyRef for the AttributedCarLibrary.dll, 615 System.Windows.Forms assembly, attributes 585 .NET AssemblyResolve event, AppDomain class, applying in C#, 606—607 640 attribute consumers, 605—606 AssemblyTrademarkAttribute attribute, C# attribute shorthand notation, 614 607—608 [AssemblyVersion] attribute, 560, 562, 660 obsolete attribute in action, 608—609 AssemblyVersionAttribute attribute, 614 overview, 604 Assets Library, 1212, 1213, 1217, 1222, specifying constructor parameters 1229, 1236, 1320, 1358 for, 608 Assign activity, 1091, 1107, 1108, 1111 assembly-level (and module-level), 612—613

1594

INDEX ■

CIL, 655 creating inventory table, 840—842 custom visually creating table relationships, applying, 610 846—847 named property syntax, 610—611 AutoLot database icon, 849 overview, 609 AutoLot project, 917 restricting usage, 611—612 AutoLotConnDAL.cs file, 862 using early binding, 614—615 AutoLotConnectedLayer class, 1409 using late binding, 615—617 AutoLotConnectedLayer namespace, 862, using to customize serialization, 823 882, 1073, 1398, 1402, 1492 XAML, 1160—1161 AutoLotCUIClient application, 871, 877, Attributes( ) method, 1000 882 Attributes property, FileSystemInfo class, AutoLotDAL (Version 2) project, 920 778 AutoLotDAL (Version 3) project, 940 AttributeTargets enumeration, 611 AutoLotDAL Code Library project, 880 [AttributeUsage] attribute, 611, 612 AutoLotDAL namespace, 984, 986, 1242 element, 1427 AutoLotDAL project, 862, 871, 882, 984 authoring animations, 1304 AutoLotDAL Version 4.0 Authorization property, 1040 invoking stored procedure, 985—986 element, 1427 mapping stored procedure, 980—981 auto attribute, 669 navigation properties, 982—985 Auto Format link, 1445 overview, 979 Auto Format option, 1399 AutoLotDAL_EF.edmx project, 979 window, 50 AutoLotDAL.AutoLotDataSetTableAdapter autocompletion, 49, 50 s namespace, 940 AutoEventWireup attribute, 1424—1425 AutoLotDAL.dll assembly autogenerated code, 932 adding disconnection functionality to autogenerated data adapter object, 932 configuring data adapters using AutoIncrement property, DataColumn SqlCommandBuilder class, 918— class, 890, 892 919 autoincrementing fields, 892 defining initial class types, 917 AutoIncrementSeed property, GetAllInventory( ) method, 919 DataColumn class, 890, 892 setting version numbers, 919 AutoIncrementStep property, testing disconnected functionality, DataColumn class, 890, 892 920—921 AutoLot (Version 2) project, 938 UpdateInventory( ) method, 919 AutoLot (Version Three) folder, 938 referencing, 1396, 1409 AutoLot Data Access Layer project, 862 AutoLotDAL.sln file, 938 AutoLot database, 849, 850, 921, 922, 953, AutoLotDataReader application, 853 954, 1492, 1493 AutoLotDataReader project, 861 adding CreditRisks table to, 879—880 AutoLotDataSet.xsd file, 938 creating AutoLotDisconnectedLayer class, 917, authoring GetPetName( ) stored 1105 procedure, 843 AutoLotDisconnectedLayer namespace, creating customers and orders 917, 945 tables, 844

1595

INDEX ■

AutoLotDisconnectionLayer namespace, BAML (Binary Application Markup 862 Language), transforming markup AutoLot.dll assembly, 927, 938, 940, 984, into .NET assembly, 1151—1152 1105, 1106, 1112 *.baml file extension, 1151, 1152 autoLotDS object, 924 base addresses, specifying, 1038—1040 AutoLotEDM_GUI application, 986 base classes AutoLotEDMClient application, 984 casting rules AutoLotEDMClient example, 986 is keyword, 250 AutoLotEntities class, 954, 959, 970, 971, as keyword, 249 974 overview, 247—248 AutoLotInventory variable, 1106 controlling creation of with base AutoLot.mdf file, 189 keyword, 228—230 AutoLotService project, 1076 libraries, role of in .NET, 8 AutoLotService.cs file, 1073 multiple, 222 AutoLotWCFService class, 1071 base keyword, 229, 237, 254, 654, 1482 automatic properties element, 1051, 1052 and default values, 208—210 BaseAddresses property, 1040 interacting with, 208 baseAddresses scope, 1039 overview, 206—207 element, 1039, 1050 automatically referenced feature, 45 BaseDirectory property, AppDomain class, autonomous entities, 1021 639 AutoPageWireUp attribute, 1425 BasedOn property, 1315 AutoPostBack property, 1431 BasedOn, Style class, 1313 AutoProps project, 206, 210 BaseStream member, BinaryReader class, AutoResetEvent class, 748—749 800 AutoResetEvent object, 1087 BaseStream member, BinaryWriter class, AutoResetEvent variable, 748 800 AutoReverse property, 1305, 1308 BASIC (Beginner's All-purpose Symbolic AutoSize property, 1526 Instruction Code), 997 Average( ) method, 516 BasicConsoleIO project, 85 BasicDataTypes project, 88, 97 BasicGreen theme, 1469 ■B BasicGreen.skin file, 1466, 1467 BasicHttpBinding class, 1029, 1031, 1037, back tick character, 594 1042, 1046, 1049, 1051, 1053, 1054, BackColor property, 1429, 1437, 1526 1070 Background and Content value, 1352 BasicHttpBinding object, 1050 Background garbage collection, 297 BasicHttpBinding option, 1029 Background property, 1133, 1160, 1161, BasicHttpBinding protocol, 1029 1273, 1293, 1297, 1301, 1353 element, 1029, 1050 Background threads, 749—750 BasicInheritance project, 219, 225 BackgroundColor property, BasicMath class, 395 System.Console class, 81 *.bat file extension, 76, 77 BackgroundImage property, 1526 bear_paper.design file, 1275 Beep( ) method, System.Console class, 81

1596

INDEX ■

beforefieldinit item, 611 binary format, serializing Begin method, 1035, 1069 DataTable/DataSet objects in, BEGIN TRANSACTION statement, 878 902—903 BeginAnimation( ) method, 1307, 1309 binary operator overloading, 445—447 BeginCatchBlock( ) method, 690 binary resources, WPF BeginClose( ) method, 1040 embedding application resources, BeginEdit( ) method, 893, 896 1289—1291 BeginExceptionBlock( ) method, 690 loose resources BeginFinallyBlock( ) method, 690 configuring, 1287 BeginInvoke( ) method, 399, 400, 732, 734, including files in project, 1286—1287 736, 738, 760, 774, 1086 overview, 1285 Beginner's All-purpose Symbolic programmatically loading images, Instruction Code (BASIC), 997 1288—1289 BeginOpen( ) method, 1040 BinaryCars.bin file, 903 BeginScope( ) method, 690 BinaryFormatter class, 529, 606, 807, 808, element, 1310 902 BeginTime property, 1305, 1308 BinaryFormatter type, 808 BeginTransaction( ) method, 834, 855, 882 deserializing, 812—813, 819 behavior, 321 serializing, 811—813 behaviorConfiguration attribute, 1043, type fidelity, 810 1055 BinaryOp class, 398, 399 behaviors element, 1042, 1043, 1050 BinaryOp delegate, 398, 399, 402, 403, 404, BenefitPackage class, 232, 234 729, 730, 732, 733, 736 BenefitPackageLevel class, 234 BinaryOp type, 738 BenefitPackageLevel enumeration, 234 BinaryOp variable, 738 BenefitsPackage type, 233 BinaryReader class, 776 beq opcode, 678 BinaryReader type, 27 Bezier curve, 1257 BinaryReaders class, 799—801 bgt opcode, 678 BinaryResourcesApp application, 1285, BigFontButton skin, 1469 1291 BigInteger class, 96 BinaryWriter class, 776 BigInteger data type, 90, 95, 96, 97 BinaryWriterReader project, 800, 801 BigInteger object, 96 BinaryWriters class, 799—801 BigInteger structure, 95 bind early, 600 BigInteger variable, 89, 96 bin\Debug folder, 602 BigInteger.Multiply( ) method, 97 binders, 709 bin directory, Mono, 1568 binding element, 1037 Bin folder, 1414, 1415 Binding keyword, 1238 Bin subdirectory, 1414 element, 1054 Binary Application Markup Language bindingConfiguration attribute, 1054 (BAML), transforming markup into BindingFlags enumeration, 592 .NET assembly, 1151—1152 element, 573 binary CIL opcodes, 655 bindings changing settings for, 1053—1054

1597

INDEX ■

DataTable objects to Windows Forms Blend window, 1211 GUIs Blend XAML editor, 1210 DataView type, 912—913 block elements, Documents API, 1227 deleting rows from DataTable, 907— Blocks (Collection) property, 1230 908 Blocks editor, 1230 hydrating DataTable from generic BlockUIContainer element, 1227 List, 904—906 blt opcode, 678 overview, 903 blue value, 717 selecting rows based on filter scope, 1383, 1386 criteria, 908—911 Boo programming language, 50, 1569 updating rows within DataTable, booc compiler, Mono, 1569 911 bool data type, 86, 93, 112, 162 early, attributes using, 614—615 bool field, 736 exposing single services using multiple, bool keyword, 89 1052—1053 bool? member, 163 HTTP-based, 1029—1030 bool parameter, 882 late bool value, 1140, 1335 attributes using, 615—617 bool variable, 88, 89, 311, 748, 1307 invoking methods with no boolArray type, 138 parameters, 602—603 Boolean data type, 162, 1479 invoking methods with parameters, Boolean expression, 1107 603—604 Boolean parameter, 298 overview, 600 Boolean property, 1235 System.Activator class, 601—602 Boolean variable, 736, 1096 MSMQ-based, 1031 Border control, 1358 overview, 1028 Border menu option, 1220 selecting, 1056—1057 BorderBrush color, 1358 TCP-based, 1030 BorderBrush property, Control Type, 1133 bindings element, 1042, 1050, 1054 BorderColor property, WebControl Base BindingSource class, 931 Class, 1437 Bitmap class, 31 BorderStyle property, 1429, 1433, 1437 Bitmap type, 1547 BorderThickness property, Control Type, BitmapImage class, 1288 1133 BitmapImage objects, 1359 BorderThickness value, 1358 BitVector32 type, 363 BorderWidth property, 1429, 1437 black box programming, 195 Bottom property, 1527 ble opcode, 678 Bounds member, 1254 Blend brush editor, 1269 Bounds property, 1527 Blend code editor, 1221 box opcode, 678 Blend Designer, 1210 boxedInt object, 364 Blend editor, 1228 boxing, 365 Blend project, 1358 boxing operation, 364 Blend Properties editor, 1209 br opcodes, 682 Blend Properties window, 1217, 1221, 1359
tag, 1435 Blend Resources window, 1321

1598

INDEX ■

bread crumbs, establishing with btnShowLogicalTree object, 1342 SiteMapPath type, 1447 btnShowVisualTree control, 1343 breadcrumbs technique, 1447 btnSpin control, 1371 break keyword, 117, 122 btnSpinner object, 1307 brower statistics, obtaining, 1419 btnSubmit button, 1505 Browse For Types option, 1095, 1106, 1107 btnUpdateDatabase class, 921 Browse tab, 57, 541, 546, 567 btnUpdateInventory control, 937 Browser property, 1418, 1419 bubbling events, 1337, 1339 Brush editors, 1171, 1260, 1269—1271, 1301 BufferedGraphics type, 1547 Brush object, 1248 BufferedStream class, 776 Brush type, 1269, 1547, 1550 BufferHeight property, System.Console brushes class, 82 configuring in code, 1260—1261 BufferWidth property, System.Console configuring using Visual Studio 2010, class, 82 1258—1260 bugs, 259—260 Brushes area, 1269 Build a Car menu item, 1447 Brushes class, 1550 Build a Car node, 1446 Brushes editor, 1222, 1269, 1358 Build Action property, 1287, 1289, 1292 Brushes type, 1547 Build menu, Visual Studio 2010, 1290 BSTR data type, 7 Build tab, 110, 657 btnAddWidgets control, 1435 build tools, automated, 43 btnCancel button, 1538 Build-a-Car, designing content page, btnCancel control, 771, 772 1455—1457 btnChangeMakes class, 911 BuildCar.aspx, 1446 btnClear control, 1226 BuildMenuSystem( ) method, 1516 btnClearPanel control, 1436 BuildTableRelationship( ) method, 923, btnDisplayMakes class, 908 924 btnDownload control, 768 Bukovics, Bruce, 1077 btnExecute control, 771 business process, defining role of WF 4.0 btnExitApp variable, 1150 in, 1078 btnExitApp_Clicked( ) method, 1150 >> button, 1212, 1213 btnGetCar button, 1474 Button class, 920, 921, 1396, 1397, 1398, btnGetOrderInfo class, 925 1399, 1408, 1409, 1422, 1423 btnGetStats control, 768 Button Click event, 1431 btnGetStats_Click( ) method, 770 Button controls, 718, 768, 1198, 1226, 1292, btnGetTextData control, 1436 1315, 1318, 1319, 1342, 1469 btnLoad control, 1226 Button element, 1160, 1202, 1338 btnOK button, 1538 Button object, implementing Click event, btnPostback button, 1477 1175—1176 btnReset class, 1387 Button property, 1534, 1535 btnSave control, 1226 Button skin, 1469 btnSetCar button, 1474 Button template, 1366 btnShow class, 1387, 1389 Button type, 1146, 1159, 1164, 1173, 1175, btnShowAppVariables button, 1486 1341, 1467, 1469 btnShowCarOnSale button, 1486 tag, 1161 building with Visual C# 2010 Express, tag, 1293 building with Visual Studio 2010 button1_Click event, 1172 Class View utility, 58—59 scope, 1161 code expansions, 63—64 scope, 1181 integrated .NET Framework 4.0 Button.HeightProperty, 1305 documentation, 67—69 Buttons control, 1262 New Project dialog box, 56 buttons, determining which was clicked, Object Browser utility, 60 1535—1536 overview, 54 Buttons widget, 1441 refactoring code, 60—63 ButtonTemplate application, 1349 Solution Explorer Utility, 56—58 ButtonTemplate project, 1356 unique features of, 55 by GetInvocationList( ) method, 404 Visual Class Designer, 64—67 by operator, 509 overview, 41 By property, Animation class types, 1305 C# compiler, 15, 32, 44, 47, 172, 605, 609, by value parameter, 160 703, 704, 1569 byte data type, 86, 108, 109, 145, 146 C# Console Application project, 263, 277 ByteAnimation class, 1304 C# language anonymous methods, 427—430, 706 custom type conversions ■C among related class types, 454—455 anonymous types, 473—478 C command, 1257 creating routines, 455—457 C string format character, 84 explicit conversions for square C# 4.0 language features types, 458 COM interoperability using, 718—724 extension methods, 460—470 COM interoperability without, 722—724 implicit conversion routines, 458— C# applications 459 and .NET Framework 4.0 Software internal representation of custom Development Kit (SDK), 41—42 conversion routines, 460 building with csc.exe numerical, 454 command line flags, 43—44 partial methods, 470—473 compiling multiple source files, 46— events 47 creating custom event arguments, overview, 42 424—425 referencing external assemblies, 45— event keyword, 419—421 46 generic EventHandler delegate, referencing multiple external 426 assemblies, 46 hidden methods of, 421 response files, 47—49 incoming, listening to, 422—423

1600

INDEX ■

overview, 418 implicitly typed local, 139 registrating, simplifying using Visual initialization syntax, 138 Studio 2010, 423—424 multidimensional, 140—141 indexer methods of objects, 139—140 definitions on interface types, 444 overview, 137 multiple dimensions, 443—444 as return values, 142 overloading, 443 System.Array class, 142—144 overview, 439—440 command-line arguments, 77—79 string values, 441—442 data type conversions LINQ query operators narrowing data conversions, 108— aggregation operations, 516—517 110 basic selection syntax, 510—511 overflow checking, 110—111 LINQ as better Venn diagramming overview, 106—107 tool, 515—516 System.Convert, 112 obtaining counts using enumerable, unchecked keyword, 111 513 enum type obtaining subsets of data, 511 declaring variables, 146—147 overview, 508—509 discovering name/value pairs of, projecting new data types, 512—513 148—150 removing duplicates, 516 overview, 144 reversing result sets, 514 System.Enum type, 147 sorting expressions, 514 underlying storage for, 145—146 operator overloading if/else statement, 120 += and -+, 448 implicitly typed local variables binary, 445—447 are strongly typed data, 115 comparison, 450 overview, 112—113 equality, 449—450 restrictions on, 114—115 internal representation of, 451—452 usefulness of, 116 overview, 444 iteration constructs unary, 448—449 do/while loop, 119 pointer types foreach loop, 118 * and & operators, 482 for loop, 117 field access with pointers, 484 while loop, 119 overview, 479—480 methods pinning types with fixed keywords, default parameter-passing behavior, 485—486 126—127 sizeof keyword, 486 named parameters, 133—134 stackalloc keyword, 485 optional parameters, 131—132 unsafe (and safe) swap function, 483 out modifier, 127—128 unsafe keyword, 481—482 overloading of, 135—137 C# programming constructs, 73—123, 125— overview, 125 165 params modifier, 130—131 application error code, 76—77 ref modifier, 128—129 arrays nullable types as arguments, 142 ?? operator, 164—165

1601

INDEX ■

overview, 162 C++ function pointer, 397 working with, 163—164 C++/Microsoft Foundation Classes (MFC), reference types 4 passing by reference, 160 cache application Graphical User Interface passing by value, 158—160 (GUI), 1492 string data Cache object, 1489, 1490 basic manipulation, 98—99 Cache property, 1416, 1421, 1489 concatenation, 99—100 Cache type, 1493 escape characters, 100—101 Cache variable, 1490 overview, 97 CacheDependency object, 1491 strings and equality, 102 CacheItemRemovedCallback delegate, strings are immutable, 102—104 1491, 1493 System.Text.StringBuilder type, Cache.NoAbsoluteExpiration field, 1491 104—105 Cache.NoSlidingExpiration field, 1491 verbatim strings, 101—102 Cache.NoSlidingExpiration parameter, structure type, 151—153 1491 switch statement, 121—123 CacheState project, 1489 system data types Calc class, 14, 15, 17 class hierarchy, 90—92 Calc.Add( ) method, 34 and new operator, 89—90 Calc.cs file, 16, 18, 33 numerical data types, 92 Calc.exe application, 35 overview, 86—87 Calc.exe assembly, 33 parsing values from string data, 94 Calc.exe file, 18, 19 System.Boolean, 93 CalculateAverage( ) method, 130, 131 System.Char, 93—94 Calc.vb code file, 16 System.DateTime, 95 control, 1439, 1455 System.Numerics, 95—97 Calendar type, 1467 System.TimeSpan, 95 call opcode, 678, 690 variable declaration, 88—89 callback functions, 397 System.Console class CallbackContract property, 1034 basic input and output with, 82—83 callbacks, 397, 398 formatting numerical data, 84—85 calling tier, 885, 886 formatting output, 83 CallMeHere( ) method, 413 overview, 81 callvirt opcode, 690 System.Environment class, 79—81 Cancel button, 1294, 1296, 1297 value types Cancel( ) method, 772, 858 containing reference types, 157—158 Cancel property, 1141 overview, 154 cancelation request, 766—767 vs. reference types, 155—156, 161— CancelButton property, 1529, 1541 162 CancelEdit( ) method, 893 variations on Main( ) method, 75—76 CancelEventArgs class, 1141 C# Snap-In, 619—620 CancelEventArgs.Cancel property, 1141 C# Windows Application solution, 51 CancelEventHandler delegate, 1141 C++ Component Object Model (COM) cancellation tokens, 766 developers, 260 CancellationScope activity, WF 4.0, 1092

1602

INDEX ■

CancellationToken property, 767 CarDelegateMethodGroupConversion CancellationTokenSource class, 766 application, 412 CancellationTokenSource object, 766, 772 CarDelegateMethodGroupConversion CancellationTokenSource token, 767 project, 413 cancelToken object, 772 CarDelegateWithLambdas project, 437 cancelToken variable, 766 CardSpace application programming CanExecute attribute, 1205 interface (API), 1023, 1030 CanExecute event, 1203, 1205 CarEngineHandler class, 406 CanExecute handler, 1205 CarEngineHandler delegate, 408, 420, 425 CanExecute property, 1205 CarEngineHandler objects, 418 CanExecuteRoutedEventArgs object, 1205 carErrors.txt file, 281 CanHelpExecute( ) method, 1204 CaretIndex property, 1200 CanRead member, Stream class, 792 CarEventArgs class, 425 CanSeek member, Stream class, 792 CarEventArgs type, 425 Canvas area, 1186 CarEvents application, 420 Canvas class, 1138, 1162, 1250, 1252 CarEvents example, retrofitting using Canvas object, 1252, 1264, 1276 lambda expressions, 436—437 Canvas panels, 1186—1188 CarEvents project, 424 Canvas scope, 1339 CarExploded( ) method, 428 Canvas type, 1188 car.gif file, 1448 tags, 1186 CarID column, 842, 890, 898 Canvas.Bottom property, 1187, 1188 CarID field, 846 Canvas.Left property, 1187, 1188 CarID key, 846 Canvas.Right property, 1187, 1188 CarID value, 843 Canvas.Top property, 1187, 1188 carIDColumn class, 892 CanWrite member, Stream class, 792 CarIDColumn column, 934 Caption property, carIDColumn object, carIDColumn object, 891, 892 891 CarID/CustID values, 844 Caption property, DataColumn class, 890 CarInfoHelper class, 684 capturing graphical output, 1557 carIsDead variable, 263 Car constructor, 584 CarIsDeadException class, 273, 274, 276, Car reference, 291 278, 279, 280, 281 Car type CarIsDeadException constructor, 281 extension methods, 465 CarIsDeadException object, 280 viewing type metadata for, 583—584 CarIsDeadException type, 274, 275 Car variable, 169, 209 CarIsDeadException.cs file, 277 CarAboutToBlow( ) method, 428 CarLibrary assembly, 538, 561 Car.Accelerate( ) method, 269, 270 CarLibrary icon, 566 carArray variable, 346 CarLibrary namespace, 532, 602 CarAvailableInZipCode( ) method, 471, CarLibrary project, 541, 545, 546 473 CarLibrary.dll assembly, 544, 545, 546, 547, Car.CarEngineHandler object, 411 568, 569, 570, 573, 574, 575 Car.cs file, 167, 206, 273, 277, 343, 571, 972 CarLibrary.EngineState enumeration, 582, CarDelegate application, 405 583 CarDelegate project, 411 CarLibrary.EngineState.engineAlive, 583

1603

INDEX ■

CarLibrary.exe file, 554 Channel property, 1046 CarLibraryPolicy.xml file, 575 char array, 98 CarLocator class, 471, 472 char data type, 87 CarLotInfo class, 1485 char keyword, 93 CarNickname property, 969, 971 char variable, 89 CarOrderApp project, 1538, 1545 character data, 102 Cars property, 955, 971, 974 Check button, 1196, 1198 Cars web site, building Check for arithmetic overflow/underflow defining default content pages, 1448— check box, 110 1449 control, 1235, 1431 designing Build-a-Car content page, Checked event, 1220 1455—1457 checked keyword, 73, 108, 109, 110, 111 designing Inventory content pages, Checked property, 1554 1450—1452 CheckInventoryWorkflowLib project, 1103 enabling in-place editing, 1454 CheckInventoryWorkflowLib.dll assembly, enabling sorting and paging, 1453 1112 master pages CheckInventory.xaml file, 1103 AdRotator widget, 1447—1448 Cherries.png file, 1358 bread crumbs, establishing with child class, 189 SiteMapPath type, 1447 ChildRelations member, 897 overview, 1442—1444 Choose Data Source dropdown box, 927, TreeView control site, 1445—1447 986, 1451 overview, 1441 CIL. See common intermediate language Cars.cd file, 224 CILCar argument, 686 carsDataSet.xml file, 901 CILCar class, 684 cascading style sheet (CSS), 1394 CILCar object, 687 case-sensitive languages, 74 CILCar parameter, 685 CaseSensitive member, 897 CILCarInfo class, 685 CaseSensitive property, 887 CILCarInfo.Display( ) method, 686 casting operations, 247, 366, 1107 CilCars example, 688 catch blocks, 267, 273, 277, 278, 279, 280, CILCars namespace, 684, 685 690 CILCars.dll assembly, 686 catch keyword, 109, 249, 261 CILCars.il file, 683 catch logic, 268, 270, 271, 277, 281 CILTypes assembly, 667 catch scope, 274, 278, 279, 281 CilTypes example, 683 catching exceptions, 266—267 CILTypes.il file, compiling, 672—673 CDATA scope, 1147 Circle class, 191, 244, 324, 328, 525 CDATA section, 1390 Circle type, 243, 246 CenterToScreen( ) method, 1530 circleOption RadioButton, 1251 -centric dot notation, 667 Class attribute, 1146, 1177 ceq opcode, 678 class constructor, 675 CGI applications, 1475 Class Designer. Name, 66 cgt opcode, 678 Class Designer Toolbox, 65, 66, 225 Change Layout Type menu option, 1211 Class Details window, 65, 66, 225 ChangeDatabase( ) method, 855 Class Diagram icon, 224

1604

INDEX ■

Class Diagram viewer, 65 internal representation of .class directive, 655, 660, 668, 669, 670, 677 properties, 202—203 class extern tokens, 551 overview, 194 class hierarchy, of system data types, 90— read-only and write-only properties, 92 204—205 Class icon, 167 static properties, 205—206 class keyword, 19, 167, 1158 using .NET properties, 198—200 class libraries, isolating strongly typed using properties within class database code into definition, 200—201 deleting data with generated codes, using traditional accessors and 942—943 mutators, 195—197 inserting data with generated codes, visibility levels of properties, 204 941—942 new keyword, 170 invoking stored procedures using object initializer syntax generated codes, 943 calling custom constructors with, overview, 938 212—213 selecting data with generated codes, inner types, 213—214 940—941 overview, 210—211 viewing generated codes, 939—940 and optional arguments, 180—181 Class Library project, 538, 547, 937, 939 overview, 167 class library relationship, 8 partial types, 217—218 Class Library template, 1023 static keyword Class member, 695 classes, 187—188 class token, 677 constructors, 185—187 class types field data, 182—185 access modifiers methods, 181—182 default, 193 this keyword and nested types, 194 chaining constructor calls using, overview, 192 176—178 automatic properties and constructor flow, 178—181 and default values, 208—210 overview, 174—175 interacting with, 208 Class View tool, 59, 939 overview, 206—207 Class View utility, Visual Studio 2010, 58— Common Type System (CTS), 19 59 constant field data Class View window, 970 constants, 214—216 Class1.cs, 711 read-only fields, 215—216 ClassDiagram1.cd file, 224 static read-only fields, 216 classes constructors abstract, 240 custom, 172 allocation onto managed heap, 291 default, 171—173 characteristics of, 19, 20 overview, 170 creating instances of, 291 conversions, 454—455 custom, 204 defining in CIL, 668—669 generic encapsulation services

1605

INDEX ■

default keyword in generic code, clients, invoking services asynchronously 390—391 from, 1067—1069 generic base classes, 391—392 client-side scripting, 1388—1390 overview, 388—389 ClientTarget property, 1416 specifying type parameters for, 372— Clip property, 1255 374 ClipGeometry property, 1255 sealed, 232 ClipToBounds property, 1265 classical inheritance, 220 Clone( ) method, 323, 350, 351, 352, 353, ClassModifier keyword, 1156, 1159 354, 888 clean entities, 990 cloneable objects, building, 349—354 Clean Solution option, Visual Studio 2010, CloneablePoint application, 349 1290 CloneablePoint project, 354 CleanUp( ) method, 311 CloneableType class, 323 Clear( ) method, 82, 143, 888, 1421, 1484, CloneMe( ) method, 323, 331 1515, 1548 cloning, 349 Clear Surface menu handler, 1556 Close( ) member ClearCollection activity, WF 4.0, 1092 BinaryReader class, 800 ClearErrors( ) method, 893 BinaryWriter class, 800 clearing, InkCanvas data, 1226—1227 Stream class, 792 CLI (Common Language Infrastructure) TextWriter class, 795 mainstream distributions, 1563—1564 Close( ) method, DatabaseReader class, role of, 1562—1563 189 Click event handler, 720, 908, 909, 925, 937, CloseConnection( ) method, 863 1251, 1337, 1338, 1398, 1419 Closed event, implementing, 1177 Click event, implementing for Button CloseMainWindow( ) method, object, 1175—1176 System.Diagnostics.Process class, Click implementation, 1343 629 ClickOnce technology, 1121, 1124 CloseTimeout property, 1040 Clicks property, 1534 Closing event, 1141, 1142 client applications, building CLR () configuring TCP-based binding, 1049— data type, 1504 1050 defined, 25—26 generating proxy code using svcutil.exe, property wrappers, 1325, 1326, 1328, 1046—1047 1330 generating proxy code using Visual clr-namespace token, 1081, 1159 Studio 2010, 1047—1048 CLS (Common Language Specification), 3, client area, invalidating, 1551 7, 23—25, 605, 612 Client Assembly, 828 [CLSCompliant] attribute, 25, 605 client element, 1042 clt opcode, 678 client proxy, refreshing, 1056—1057 cnStr value, 849 client tier, 885, 886 Code activity, 1109—1111 element, 1046 code annotations, 604 ClientBuild.rsp file, 1577 code, autogenerated, 932 Client.cs file, 552 Code Definition window, 608 ClientRectangle property, 1527 code expansions, Visual Studio 2010, 63—64

1606

INDEX ■

code file model, 1401 applying LINQ queries to nongeneric code files collections, 507—508 building Web pages using, 1406—1411 filtering data using OfType( ), 508 updating, 1409—1410 overview, 505 code library, 532 CollectionCount( ) method, System.GC code reuse, 190, 532 class, 298 code snippet edit mode, 63 collection/object initialization syntax, 491 element, 1147 collections CodeActivity activity, 1109 nongeneric, applying LINQ queries to, CodeActivity value, 1109 507—508 CodeActivityContext, 1109 of objects, serializing, 816—817 element, 556, 576—577 person only, 368 value, 598 .Collections.Specialized namespace, 363 CodeBaseClient application, 576, 577 colon operator, 133, 177, 220, 223, 393 CodeBaseClient project, 577 Color class, 1261 code-behind files, building WPF color coding, 49 applications using Color enum, 194 MainWindow class, adding code file Color object, 1225, 1261 for, 1165 Color property, 1110, 1258 MyApp class, adding code file for, 1166 color selector, 1259 processing files with .exe, Color type, 1547 1166—1167 ColorAnimation class, 1304 code-behind technique, 1392, 1406 ColorAnimation type, 1304 code-conversion utility, 51 ColorChanged handler, 1221 CodeFile attribute, 1408 ColorChanged( ) method, 1224, 1225 CodePage attribute, 1401 ColorColumn column, 934 codes ColorConverter class, 1225 deleting data with, 942—943 Colors enumeration, 1261 inserting data with, 941—942 Column Properties editor, 842 invoking using stored procedures, 943 element, 1191 selecting data with, 940—941 ColumnMapping property, DataColumn viewing, 939—940 class, 890 element, 1415 ColumnName property, DataColumn coding class, 890 keyword color, 49 Columns class, 890, 891 against ServiceHost type, 1038 Columns collection, 900, 941, 943 Collapse or Expand option, 329 Columns indexer, 934 Collect( ) method, 298, 300 Columns property, 890, 892 Collection (Items) dialog box, 1218 COM (Application Component Object Collection (Items) property, 1217, 1219 Model) object, 1483 collection activities, WF 4.0, 1092—1093 COM (C++ Component Object Model) collection objects, applying LINQ queries developers, 260 to COM (Component Object Model) accessing contained subobjects, 506— classes, 5 507 clients, 261

1607

INDEX ■

frameworks, 889 command-line arguments, C# interfaces, 261 programming, 77—79 objects, 1483 command-line compiler, 537, 550, 552 programming language comparison, 5— command-line parameters, 43, 76 6 CommandText property, 858, 867, 870 servers, 5 CommandTimeout member, 858 COM (Session Component Object Model) CommandTimeout property, 959 object, 1483 CommandType enum, 858 COM interoperability CommandType property, 858 simplifying using dynamic data CommandType.StoredProcedure value, common COM interop pain points, 870 717—718 Commit( ) method, 879, 882 embedding interop metadata, 716— COMMIT statement, 878 717 committed transactions, 878 overview, 714 Common Controls section, 1544 role of Primary Interop Assemblies common dialog boxes category, 1512 (PIAs), 715 common intermediate language (CIL) using C# 4.0 language features, 718—724 .NET base class library, C#, and CIL without C# 4.0 language features, 722— data type mappings, 673 724 and assemblies COM+ layer, 1016 benefits of, 16—17 COM+ objects, 1015, 1022 compiling to platform-specific COM+/Enterprise Services, 1015 instructions, 17 Combine menu, 1268 overview, 14—15 Combine( ) method, 401 attributes, role of, 655 CombinedGeometry class, 1255 building .NET assembly with ComboBox control, Ink API tab, 1224—1226 building CILCarClient.exe, 686—687 ComboBoxItem control, 1218, 1225 building CILCars.dll, 683—686 ComboBoxItem objects, 1219, 1225 compiling CILTypes.il file, 672—673 comboColors control, 1219 defining and implementing interfaces comContracts element, 1042 in, 670 comma-delimited list, 130, 393 defining class types in, 668—669 command builder type, 918 defining current assembly in, 667 command line, generating strong names defining enums in, 671 at, 561—563 defining field data in, 674—675 Command object, 827, 828, 834 defining generics in, 671—672 command prompt defining member parameters, 676—677 Mono, 1568, 1572, 1577 defining namespaces in, 668 Visual Studio 2010, 33, 534 defining properties in, 676 Command property, connecting WPF defining structures in, 670—671 commands to, 1202—1203 defining type constructors in, 675 CommandBinding objects, 1203 defining type members in, 674—677 definitions, 1205 directives, role of, 655 CommandBindings collection, 1205 exploring assemblies using ildasm.exe, CommandCollection property, 937 34

1608

INDEX ■

opcodes data types, 22—23 .maxstack directive, 680 delegate types, 21—22 declaring local variables in CIL, 680— enumeration types, 21 681 interface types, 20 hidden this reference, 682 structure types, 20 mapping parameters to local type members, 22 variables in CIL, 681 commonBehaviors element, 1042 overview, 677—679 CommonSnappableTypes namespace, 621 representing iteration constructs in CommonSnappableTypes.dll assembly, CIL, 682—683 618, 619, 621, 622 role of, 655 CommunicationState enumeration, 1041 overview, 653 Company property, 206 reasons for learning grammar of, 653— [CompanyInfo] attribute, 619, 623 654 CompanyInfoAttribute attribute, 619 round-trip engineering companyName field, 206 authoring CIL code using comparable objects, building SharpDevelop, 665—666 custom properties, custom sort types, compiling CIL code using ilasm.exe, 358 663—664 overview, 354—356 interacting with CIL, 662—663 specifying multiple sort orders overview, 658—660 (IComparer), 357—358 role of CIL code labels, 661—662 ComparableCar application, 355 role of peverify.exe, 666 ComparableCar project, 359 specifying externally referenced Compare( ) method, 97, 383 assemblies in, 666 CompareExchange( ) method, Interlocked stack-based nature of, 656—658 class, 756 Common Language Infrastructure (CLI) CompareTo( ) method, 355, 356 mainstream distributions, 1563—1564 CompareValidator control, 1458 role of, 1562—1563 CompareValidator type, 1459 Common Language Runtime (CLR) CompareValidator widget, 1461—1462 data type, 1504 comparison operator overloading, 450 defined, 25—26 CompensableActivity activity, WF 4.0, 1092 property wrappers, 1325, 1326, 1328, Competed event, 1091 1330 compilation cycle for multifile pages, 1410 Common Language Specification (CLS), 3, compilation cycle for single-file pages, 7, 23—25, 605, 612 1405—1406 Common Object Request Broker element, 1410 Architecture (CORBA), 1014 elements, 1166 Common Object Runtime compiler error, 88, 128, 132 Engine, 25 compiler flags, 44 Common Properties area, 1214, 1218, compile-time error, 115, 139 1220, 1236 Complain( ) method, 181, 182 Common Properties section, 1217, 1219 Completed event, 1307 Common Type System (CTS) Completed property, 1088 class types, 19 Complex structure, 95

1609

INDEX ■

Component, 1301 connection string, 854, 856 Component Object Model. See COM Connection String property, 849 component tray, 931 connection timeout setting, 855 ComponentCommands class, WPF, 1201 ConnectionState enumeration, 855, 856 components category, 1512 ConnectionState values, 856 composition, of applications, 1025—1027 ConnectionState.Closed value, 856 Concat( ) method, 516 ConnectionState.Open value, 856 concatenation, of string data, 99—100 connectionString attributes, 852 concatenation symbol, 1094 ConnectionString property, 849, 855, 857, conceptual model, 958 1451 concurrency, 728—729, 750—758 element, 1504 concurrent garbage collection, 297 ConnectionStringBuilder objects, 856—857 Condition editor, 1107 element, 847, 852— Condition property, 1097 853, 871, 932, 1427, 1451 conditional code compilation, partial value, 1451 methods, 472 ConnectionTimeout property, 855 *.config file extension, 554 Consistent, 878 *.config files, 555, 556, 569, 570, 573, 574, Console Application project, 273, 712 848, 849, 850, 852, 853 Console class, 28, 75, 81, 82, 181 configuration files, altering using Console namespace, 30, 532 SvcConfigEditor.exe, 1059—1061 Console project, 712 element, 555, 1415 Console type, 82, 754 ConfigurationManager class, 1427 console user interface (CUI), 81 ConfigurationManager type, 839 Console window, 566 ConfigurationManager.AppSettings Console.Beep( ) method, 312 indexer, 849, 852 ConsoleClientApp.cs, 1576 ConfigurationManager.ConnectionStrings ConsoleClientApp.exe, 1578 indexer, 852 ConsoleClientApp.exe file, 1576, 1577 ConfigurationName property, 1034 ConsoleColor enumeration, 81 ConfigureAdapter( ) method, 917, 918 ConsoleColor variables, 133 ConfigureCUI( ) method, 62 Console.ReadLine( ) method, 61, 75, 750, ConfigureGrid( ) method, 1242 875, 1095 configuring tab order, 1540 Console.WriteLine( ) method, 83, 136, 178, configuring TCP-based binding, 1049—1050 366, 430, 434, 551, 663, 690, 731 Connect( ) method, 1151 const keyword, 214, 218 Connect Timeout segment, 855 constant field data connected layer, of ADO.NET constants, 214—216 command objects, 858 read-only fields, 215—216 connection objects, 854—856 static read-only fields, 216 ConnectionStringBuilder objects, 856— ConstData project, 214, 217 857 Constraint type, System.Data namespace, overview, 853 832 Connection member, 858 constraints, 361 connection object, 827, 833, 839 Constraints member, 897 Connection property, 853, 858, 879, 959 ConstructingXmlDocs application, 1002

1610

INDEX ■

ConstructorBuilder, DefineProperty( ) ContextBoundObject class, 757 method, 696 Context.Cache property, 1488 ConstructorBuilder member, 689 Context.Cache.Insert( ) method, 1490 ConstructorBuilder type, 690, 696 context.Inventories, 1242 constructors ContextMenu property, arguments, 205 FrameworkElement type, 1133 chaining calls, 176—178, 180, 199 contextual boundaries, AppDomain, 625 for classes contextual keyword, 199 custom, 172 continue keyword, 117 default, 171—173 contract element, 1037 overview, 170 contracts definition, single, 180 data, 1070—1076 emitting, 696—697 operational, service types as, 1035—1036 flow of, and this keyword, 178—180 WCF, 1027 static, 185—187 contravariance, 9, 10, 414 contained controls, enumerating, 1432— Control class, 1132, 1314, 1404, 1416, 1512, 1435 1515, 1526—1529 ContainerControl class, 1529 control declarations, ASP.NET, 1403—1404 containers control flow activities, WF 4.0, 1089 generating documents from, 1004—1005 Control Flow area, 1104 type-safe, 367 Control Library section, 1184 ContainerVisual class, 1277 , 1500 ContainerVisual object, 1258 Control property, 1537 containment, programming for, 232—235 control templates, WPF containment/delegation model, 190, 219, building custom with Visual Studio 232 2010 Contains( ) method, 97, 98 {TemplateBinding} markup content display area, 1354 extension, 1352—1353 content model, WPF, 1226 ContentPresenter, 1354 content pages incorporating templates into styles, default, 1448—1449 1354—1355 designing, 1455—1457 incorporating visual cues using Content property, 1131, 1132, 1181, 1185, triggers, 1351—1352 1218, 1219, 1236, 1238, 1353, 1354 overview, 1348 ContentControl class, 1117, 1131, 1132, templates as resources, 1349—1351 1181, 1185 default ContentEncoding property, 1421 overview, 1341—1343 ContentPlaceHolderID value, 1449 programmatically inspecting, 1344— ContentPresenter class, 1344, 1352, 1354 1348 ContentProperty class, 1241 Control type, 1132, 1133, 1346, 1437 ContentType property, 1421 control-agnostic events, 1200 context 0 (default context), application ControlBox property, 1529 domain, 648 ControlCollection object, 1432 context attributes, 649 controls. See also ASP.NET web controls Context property, 1489, 1490 collection, populating, 1515—1517

1611

INDEX ■

contained, enumerating, 1432—1435 Copy Local property, 568 created dynamically, 1436—1437 Copy( ) method, 888, 897 dynamically adding and removing, Copy to Output Directory property, 1008, 1435—1436 1287, 1289 dynamically created, 1436—1437 CopyTo( ) method for validation Array class, 143 CompareValidator widget, 1461— FileInfo class, 785 1462 CopyToDataTable( ) method, 948 creating summaries, 1462—1463 CORBA (Common Object Request Broker defining groups, 1463—1465 Architecture), 1014 overview, 1457—1458 core assemblies of Windows RangeValidator widget, 1460—1461 Communication Foundation RegularExpressionValidator widget, (WCF), 1022 1460 core infrastructure category, 1512 RequiredFieldValidator widget, Core user input controls, WPF, 1179 1459—1460 CoreLibDumper class, 1572 WebControl base class, 1437—1438 CoreLibDumper.dll, assigning strong Controls node, 1229 name to, 1574 Controls property, 1432, 1515, 1516, 1527 CoreLibDumper.dll library, 1572 Controls.Add( ) method, 1515 cores, 761 ControlsCollection class, 1515 CorLibDumper folder, 1572, 1575 ControlsCollection container, 1515 CorLibDumper project, 1580 ControlTemplate class, 1344 CorLibDumper.dll assembly, 1574, 1575, ControlTemplate object, 1348 1577, 1578 tag, 1351 CorrelationScope activity, WF 4.0, 1090 collection, corrupted state exceptions (CSE), 285, 286 1352 Count( ) method, 513, 516, 1515 ControlToValidate property, 1458, 1459, Count property, 934, 1484 1461 Count<>( ) method, 509 conversion routines, custom, 460 covariance, 9, 10, 414 conversions, numerical, 454 CPU-agnostic intermediate language, 536 Convert class, 112 CrazyOrange folder, 1467 Convert( ) method, 1241 CrazyOrange theme, 1467, 1469 Convert to New Resource option, 1301 CrazyOrange.skin file, 1467 Convert type, 112 Create( ) method ConvertBack( ) method, 1241 DirectoryInfo class, 778 Cookie collection, 1498 FileInfo class, 785, 786 cookies FileMode enumeration, 787 creating, 1498—1499 Create New SQL Server Database menu overview, 1497 option, 840 reading incoming data, 1499 CREATE PROCEDURE statement, 843 Cookies property, 1418, 1421 CreateCommand( ) method, 322 CookieStateApp project, 1498 CreateDataReader( ) method, 900, 944 cool factor, 600 CreateDataTable( ) method, 906 Copy command, 1200 CreateDataView( ) method, 912

1612

INDEX ■

CreateDomain( ) method, AppDomain CSharpSnapIn project, 619, 620 class, 638 CSharpSnapIn.dll assembly, 618, 621, 623 CreateInstance( ) method, 601, 638 *.csproj file, 1148, 1150, 1151, 1166 CreateMyAsm( ) method, 691, 692, 693, CSS (cascading style sheet), 1394 697 CssClass property, WebControl Base Class, CreateNew member, FileMode 1438 enumeration, 787 CssStyle property, 1465 CreateObject ( ) method, 959 C-style function pointer, 21 CreateSalesMemoActivity.cs, 1109 .ctor directive, 675 CreateSubdirectory( ) method, ctor token, 675, 689 DirectoryInfo class, 778, 781 Ctrl+M keystroke, 544, 581 CreateText( ) method, FileInfo class, 785, Ctrl+Z , 1268, 1523 789 CTS (Common Type System) CreateThread( ) function, 626 class types, 19 CreateUsingLateBinding( ) method, 602 data types, 22—23 CreationTime property, FileSystemInfo delegate types, 21—22 class, 778 enumeration types, 21 Credentials property, 1040 interface types, 20 CreditRisks table, adding to AutoLot structure types, 20 database, 879—880 type members, 22 cross-language inheritance, 549 CTS (enumeration types, Common Type *.cs extension file, 45, 289 System), 21 *.cs file extension, 43, 46, 47, 50, 55, 217 CType operator, 1107 csc (C-sharp compiler), 42 cubic Bezier curve, 1257 csc.exe compiler, 15, 24, 41, 43, 45, 46, 47, CUI (console user interface), 81 48, 1149 curly brackets, 83, 138 csc.exe file, building C# applications with currBalance field, 183 command line flags, 43—44 Current ( ) method, 344 compiling multiple source files, 46—47 Current Inventory table, 916 overview, 42 Current property, Application class, 1129 referencing external assemblies, 45—46 Current value, 896 referencing multiple external currentColor variable, 1556 assemblies, 46 CurrentContext property, response files, 47—49 System.Threading.Thread Class, csc.rsp response file, 48 741 CSE (corrupted state exceptions), 285, 286 CurrentDomain property, AppDomain C-sharp compiler (csc), 42 class, 639 CSharpCarClient application, 546 CurrentNumber property, 1333, 1334, CSharpCarClient project, 546, 547 1335, 1336 CSharpCarClient.exe application, 553 CurrentNumberChanged( ) method, 1336 CSharpCarClient.exe file, 547, 553, 554, 555 CurrentPriority member, ProcessThread CSharpCarClient.exe.config file, 554, 555, type, 633 557 currentShape variable, 1251, 1252, 1555 CSharpModule class, 619 CSharpModule type, 620

1613

INDEX ■

CurrentThread property, resolving name clashes with aliases, System.Threading.Thread Class, 528—530 741 resolving name clashes with fully currentVideoGames array, 519 qualified names, 527—528 currentVideoGames variable, 500 custom objects, persisting, 1507—1509 currInterestRate field, 183, 185 .custom tokens, 542, 544 currInterestRate variable, 186 custom type conversions currPay field, Employee class, 196 among related class types, 454—455 currSpeed field, 170, 686 anonymous types Cursor property, 1133, 1198, 1526 containing anonymous types, 478 curves, cubic Bezier, 1257 equality for, 476—478 CustID field, 846 internal representation of, 474—475 CustID key, 846 overview, 473 CustID parameter, 882 ToString( ) and GetHashCode( ), 476 CustID value, 845 creating routines, 455—457 custom attributes explicit conversions for square types, applying, 610 458 named property syntax, 610—611 extension methods overview, 609 extending interface types with, 469— restricting usage, 611—612 470 custom classes, 204, 758 extension libraries, 467—468 custom constructor, 153 importing types that define, 465—466 custom conversion routines, internal IntelliSense mechanism, 466—467 representation of, 460 invoking on instance level, 463 custom event arguments, creating, 424— invoking statically, 464 425 overview, 460—462 custom exceptions, building, 273—276 scope of, 464—465 custom interfaces, defining, 325—327 implicit conversion routines, 458—459 custom , rendering to, internal representation of custom 1280—1282 conversion routines, 460 custom metadata viewer numerical, 454 displaying various odds and ends, 592 partial methods, 470—473 fields and properties, 591 custom view state data, adding, 1478—1479 generic types, 594 CustomAttribute tokens, 586 implemented interfaces, 591 CustomAttributeBuilder member, 689 implementing Main( ) method, 592—593 CustomBinding class, 1028 method parameters and return values, CustomConversions project, 455, 460 594—595 CustomDepPropApp application, 1331 methods, 590 CustomDepPropApp project, 1337 overview, 590 CustomEnumerator project, 345 custom namespaces, defining CustomEnumeratorWithYield application, creating nested namespaces, 530 346 default namespace of Visual Studio CustomEnumeratorWithYield project, 349 2010, 531 element, 1427 overview, 525—526

1614

INDEX ■

customers table, creating in AutoLot public point of, 199 database, 844 read-only field, 215 CustomException class, 273 selecting with generated codes, 940— CustomException namespace, 343 941 CustomException project, 273 stack-based, 366 CustomGenericMethods application, 385 data access library, ADO.NET, reusing CustomGenericMethods project, 388 adding connection logic, 863 CustomInterface application, 325 adding deletion logic, 865 CustomInterface project, 335 adding insertion logic, 863—864 customizing Soap/Binary serialization adding selection logic, 866 processes adding update logic, 865 overview, 818—819 executing stored procedure, 869—871 using attributes, 823 overview, 861—862 using ISerializable, 820—822 parameterized command objects, 867— CustomNamespaces application, 525 869 CustomNamespaces namespace, 527 data access logic, adding, 1397—1401 CustomNamespaces project, 531 data adapter class, 913 CustomNamespaces.exe assembly, 525 data adapters CustomSerialization project, 821 configuring using SqlCommandBuilder CustomValidator control, 1458 class, 918—919 CustomVisualFrameworkElement class, mapping database names to friendly 1283 names, 916 CustomVisualFrameworkElement objects, overview, 913 1281 prepping, 922—923 Cut command, 1200 simple data adapter example, 914—915 Cut operation, 1202 strongly typed, 936—937 C/Windows application programming data allocation, in-memory, 183, 184 interface (API), 4 data binding entities, to Windows Forms GUIs, 986— 989 ■D WPF Data Binding tab, 1236 D command, 872 DataContext property, 1239 D string format character, 84 DataGrid tab, 1242—1244 daemon threads, 750 establishing data bindings, 1236— dash (-) symbol, 44 1238, 1241—1242 data IValueConverter interface, data 2D graphical, 1254 conversion using, 1240—1241 deleting with generated codes, 942—943 overview, 1235 inserting with generated codes, 941— Data Binding option, 1236 942 Data Binding tab, WPF, 1214, 1236 interactive graphical, 1246 data caching, 1489—1491 interoperability, 716 Data Connections node, 840 private, 195 data contracts, designing private points of, 207 examining Web.config files, 1075

1615

INDEX ■

implementing service contracts, 1073— data type variable, 90 1074 data types overview, 1070 Common Type System (CTS), 22—23 role of *.svc files, 1074 nullable, 837 testing services, 1075—1076 data validation logic, 210 using Web-Centric service project DataAdapter object, 828 templates, 1071—1073 Database Diagrams node, 846 Data Control Language (DCL), 885 Database Explorer window, 840 Data Definition Language (DDL), 885 Database Management System (DBMS), data parallelism, 763—766 827, 829, 830, 886 data points, 189 database management systems (DBMS), Data property, 270—272, 274, 1101, 1254, 830, 851, 867 1255, 1256, 1257, 1267 database names, mapping to friendly data provider factory model, ADO.NET names, 916 element, 852—853 Database property, 855 complete data provider factory database tables, updating, 924 example, 848—851 database transactions, ADO.NET overview, 847 adding CreditRisks table to AutoLot potential drawback with provide database, 879—880 factory model, 851—852 adding transaction method to data providers, ADO.NET InventoryDAL class, 880—882 abstracting using interfaces, 837—840 key members of transaction object, Microsoft-supplied, 829—830 878—879 overview, 827—828 overview, 877 system.Data.OracleClient.dll, 830—831 testing, 882—883 third-party, obtaining, 831 DatabaseReader class, 164, 189 data readers, ADO.NET, 859—861 DataBind( ) method, 1432 data relationships and multitabled DataSet data-binding logic, 1236 objects data-binding model, WPF, 1135 building table relationships, 924 DataColumn class, 885, 887, 889, 890, 891, navigating between related tables, 925— 892, 894, 904 927 DataColumn objects, 886, 890, 891, 892, overview, 921 893, 898, 906 prepping data adapters, 922—923 DataColumn types updating database tables, 924 adding objects to DataTable types, 892— Data Source Configuration Wizard, 928, 893 931, 933, 936 building, 891—892 Data Source name, 854 enabling autoincrementing fields, 892 data templates, 1244 overview, 889—890 data type conversions System.Data namespace, 832 narrowing data conversions, 108—110 DataContext property, 1239 overflow checking, 110—111 [DataContract] attribute, 1027, 1070 overview, 106—107 DataGrid control, 1242 System.Convert, 112 DataGrid objects, 1235 unchecked keyword, 111 DataGrid tab, WPF, 1214, 1242—1244

1616

INDEX ■

DataGridView class, 903, 904, 906, 907, DataRow.EndEdit( ) method, 896 912, 920, 921, 924, 927, 928 DataRowExtensions class, 946 DataGridView control, 927—932 DataRowExtensions.Field( ) Extension DataGridView object, 906, 921, 986 method, 948 DataGridView widget, 322 DataRow.RejectChanges( ) method, 897 DataGridView wizard, 939 DataRows, strongly typed, 935 dataGridViewCustomers widget, DataRowState enumeration, 894, 895 DataGridView class, 921 DataRowState property, 896 DataGridViewDataDesigner project, 927, DataRowVersion enumeration, 896 938 DataRowVersion property, 896—897 dataGridViewInventory widget, DataSet class, 885, 886, 932, 933, 937, 938, DataGridView class, 921 939, 1420, 1479, 1488 dataGridViewOrders widget, DataGridView DataSet container, 951 class, 921 Dataset Designer, Visual Studio 2010, 933 dataGridYugosView class, 912 DataSet extensions library, 945—946 [DataMember] attribute, 1027, 1070, 1071 DataSet member, 897 DataParallelismWithForEach application, DataSet model, 929 763 DataSet objects, 494, 864, 885, 886, 899, DataParallelismWithForEach project, 768 932, 945, 946, 951 DataProviderFactory application, 848, 853 DataSet types DataProviderFactory project, 853 building, 889 DataProviderFactory.exe assembly, 848 key methods of, 888 DataReader class, 900 key properties of, 887 DataReader object, 827 overview, 886 DataRelation class, 885, 887, 925 programming to with LINQ DataRelation collection, 921 DataSet extensions library, 945—946 DataRelation objects, 921, 924 obtaining LINQ-compatible DataRelation type, System.Data datatables, 946—947 namespace, 832 overview, 943—944 DataRelationCollection class, 887 populating new DataTables from DataRow class, 885, 893, 895, 896, 934, 935, LINQ queries, 948—950 939, 941, 946, 947 role of DataRow indexers, 948 DataRowExtensions.Field( ) DataRow objects, 886, 893, 894, 895, 896, , 948 907, 908, 916, 947 System.Data namespace, 832 DataRow type DataSetName property, 887 DataRowVersion property, 896—897 DataSets overview, 893 inserting DataTables into, 898 RowState property, 894—896 obtaining data in, 898—899 DataRow type, System.Data namespace, strongly typed, 932—934 832 DataSet.WriteXml( ) method, 890 DataRow.AcceptChanges( ) method, 896 DataSource property, 855, 906, 913, 921, DataRow.BeginEdit( ) method, 896 949 DataRow.CancelEdit( ) method, 896 DataSourceID property, 1446, 1447, 1450, DataRowCollection class, 895 1451

1617

INDEX ■

DataTable class, 866, 885, 886, 888, 891, strongly typed, 934 892, 935, 936, 937, 939 dataToShow variable, 1342 DataTable objects, binding to Windows DataType property, DataColumn class, 890 Forms GUIs DataTypeFunctionality( ) method, 93 DataView type, 912—913 DataView class, 885, 912, 913, 949 deleting rows from DataTable, 907—908 DataView object, 904 hydrating DataTable from generic DataView type, 832, 912—913 List, 904—906 DatePicker control, 1347 overview, 903 DateTime class, 132 selecting rows based on filter criteria, DateTime structure, 95 908—911 DateTime type, 85, 95 updating rows within DataTable, 911 DateTime variable, 89 DataTable type DateTime.Now.AddSeconds(15) adding objects to, 892—893 parameter, 1491 inserting into DataSets, 898 DbCommand class, 827, 847, 957 obtaining data in DataSets, 898—899 DbCommand type, 858 overview, 897 DbConnection class, 827, 837, 847, 855, processing data using DataTableReader 957 objects, 899—901 DbDataAdapter class, 828, 847, 886, 913, serializing DataTable/DataSet objects 914 as XML, 901—902 DbDataReader class, 827, 847 serializing DataTable/DataSet objects DbDataReader object, 858 in binary format, 902—903 DbDataReader type, 859 System.Data namespace, 832 DBMS (Database Management System), DataTable variable, 906 827, 829, 830, 886 DataTable.AcceptChanges( ) method, 896 DBMS (database management systems), DataTableCollection class, 887 830, 851, 867 DataTableCollection type, 443 DbParameter class, 828, 847 DataTable/DataSet objects DbParameter objects, 858 serializing as XML, 901—902 DbParameter type, specifying parameters serializing in binary format, 902—903 using, 867—869 DataTableExtensions class, 946, 947 DbProviderFactories class, 848 DataTableMapping class, 916 DbProviderFactory class, 848 DataTableMappingCollection collection, DbProviderFactory object, 848 916 DbTransaction class, 828, 847 DataTable.NewRow( ) method, 894 DbType property, 868 DataTableReader class, 900, 1074 DCL (Data Control Language), 885 DataTableReader objects, using to DCOM (Distributed Component Object processing data, 899—901 Model), 1014—1015, 1019 DataTableReader type, System.Data DDL (Data Definition Language), 885 namespace, 832 Deactivate event, 1531, 1532, 1533 DataTables class deactivated, 1531 hydrating from generic List, 904— Debug folder, 76, 546, 1114, 1149, 1287 906 Debug tab, Visual Studio 2010, 79, 80 populating from LINQ queries, 948—950 debugging ASP.NET pages, 1410—1411

1618

INDEX ■

DecelerationRatio property, Timeline definitions on interface types, 444 class, 1305 Delay activity, WF 4.0, 1091 decimal data type, 87 Delegate, 412 DeclareImplicitVars( ) method, 113 delegate keyword, 21, 398, 399, 400, 401, DeclareLocal( ) method, 690 432 Decrement( ) method, 756, 757 delegate variable, 412 dedicated databases, storing session data Delegate.Combine( ) method, 409, 421 in, 1502 DelegateCovariance application, 413 deep copy, 350 DelegateCovariance project, 415 default , 638 delegate/event model, 9 default constructor, 89, 153, 211, 212, 393 Delegate.Remove( ) method, 410, 421 default content pages, 1448—1449 delegates default context (context 0), application .NET delegate type, 397—398 domain, 648 asynchronous nature of Default edit area, 1107 BeginInvoke( ) and EndInvoke( ) default endpoints, 1051—1052 methods, 732 default input button, setting, 1541 overview, 731 default keyword, 390 System.IAsyncResult interface, 732— Default namespace option, 531 733 Default property, 1106 defining delegate type in C#, 398—400 Default value, 896, 1368 delegate covariance, 413—415 Default.aspx file, 1446, 1449, 1468, 1469, generic, 415—418 1493, 1505, 1506 method group conversion syntax, 411— Default.aspx page, 1496, 1505 413 DefaultDrawingAttributes property, 1224 sending object state notifications using defaultProvider, 1505 enabling multicasting, 408—409 default(T) syntax, 390 overview, 405—407 defaultValue attribute, 1504 removing targets from delegate's DefaultValue property, DataColumn class, invocation list, 410—411 890 simplest possible delegate example, DefaultView member, 897 402—404 DefineConstructor( ) method, 696 System.MulticastDelegate and DefineDefaultConstructor( ) method, 697 System.Delegate base classes, 400— DefineDynamicModule( ) method, 694 401 DefineEnum( ) method, 694 delegation, programming for, 232—235 DefineLabel( ) method, 690 DELETE command, 914 DefineMethod( ) method, 697 delete keyword, 9, 289 DefineResource( ) method, 694 Delete( ) method DefineType( ) method, 694 DataRow class, 895, 907 defining Directory class, 783 groups, 1463—1465 DirectoryInfo class, 778 user profiles within Web.config, 1504— FileInfo class, 785 1505 FileSystemInfo class, 778 DefiningGeometry property, Shape class, Delete statement, 861, 862, 1450 1248 Delete Sticky Note button, 1234

1619

INDEX ■

DeleteCar( ) method, 875 Design tab, SharpDevelop, 52 DeleteCommand property, 914, 918, 949 designer toolbox, SharpDevelop, 52 Deleted value, 895 element, 970 DeleteObject( ) method, 959, 975, 976 .Designer.cs file, 1520 deleting records, 974—975 *.Designer.cs files, 1521 Delta property, 1535 desktop applications, WPF and XAML, demonstrating view state, 1477—1478 1121—1123 dependency properties, WPF desktop markup, 1119 building custom, 1331—1336 desktop program, navigation-based, 1124 CLR property wrappers, 1330 Detached value, 895 examining existing, 1327—1330 development web server, ASP.NET, 1382 overview, 1325—1326 diagnostics element, 1043 DependencyObject class, 1135, 1326 dialog boxes DependencyObject parameter, 1335, 1336 designing DependencyProperty field, 1326, 1330 configuring tab order, 1540 DependencyProperty object, 1328, 1330, DialogResult property, 1539 1336 displaying dialog boxes, 1542—1543 DependencyProperty variable, 1326 overview, 1538 DependencyPropertyChangedEventArgs setting form's default input button, parameter, 1335 1541 DependencyProperty.Register( ) method, Tab Order Wizard, 1540—1541 1326, 1328, 1329, 1335 understanding form inheritance, element, 573, 574 1543—1545 deprecated, 830 WPF, 1183 Dequeue( ) method, 382, 383 Dialog class, 1538 derived class, casting rules DialogResult enumeration, 1539 is keyword, 250 DialogResult property, 1539 as keyword, 249 DialogResult type, 1532 overview, 247—248 DialogResult values, 1542, 1553 derived types, 323, 324 diamond button, 1293 DerivedCars.cs file, 540 dictionaries, merged resource, 1298—1299 DESC (descending), 910 Dictionary object, 1088, 1105 DescendantNodes( ) method, 1000 Dictionary<> object, 1094 Descendants( )method, 1008 Dictionary<> variable, 1086 Descendants method, 1000 Dictionary object, 952 descending (DESC), 910 Dictionary variable, 1084 descending operator, 509, 514 Dictionary class, 377 Description property, 610, 615, 1065 DictionaryEntry type, 271 Desendants( ) method, 1001 digital signature, 560, 561 deserialization, defined, 804 dimensions, indexers with multiple, 443— Deserialize( ) method 444 BinaryFormatter type, 811, 813 direct event, 1338 IFormatter interface, 809 Direct Selection button, 1213 SoapFormatter type, 813 Direction property, 843, 868, 871 deserializing objects, 812—813 directives

1620

INDEX ■

ASP.NET, 1401—1403 overview, 903 role of CIL, 655 selecting rows based on filter directly creating types, 797—798 criteria, 908—911 Directory class, 776, 777 updating rows within DataTable, Directory method, FileInfo class, 785 911 Directory types, 782—783 data adapters DirectoryApp project, 783 mapping database names to friendly Directory.GetFiles( ) method, 764 names, 916 DirectoryInfo class, 776, 777 overview, 913 DirectoryInfo types simple data adapter example, 914— abstract FileSystemInfo base class, 777— 915 778 DataColumn types creating subdirectories with adding objects to DataTable types, DirectoryInfo type, 781—782 892—893 enumerating files with DirectoryInfo building, 891—892 type, 780—781 enabling autoincrementing fields, DirectoryName method, FileInfo class, 785 892 DirectX layer, 1120 overview, 889—890 dirty entities, 990 DataRow type dirty window, 1549 DataRowVersion property, 896—897 DisableAllButton style, 1319 overview, 893 Disassembler window, 36 RowState property, 894—896 disco utility, Mono, 1571 DataSet types disco.exe utility, Microsoft .NET, 1571 building, 889 disconnected functionality, testing, 920— key methods of, 888 921 key properties of, 887 disconnected layer, of ADO.NET overview, 886 adding disconnection functionality to DataTable type AutoLotDAL.dll inserting into DataSets, 898 configuring data adapters using obtaining data in DataSets, 898—899 SqlCommandBuilder class, 918— overview, 897 919 processing data using defining initial class types, 917 DataTableReader objects, 899—901 GetAllInventory( ) method, 919 serializing DataTable/DataSet setting version numbers, 919 objects as XML, 901—902 testing disconnected functionality, serializing DataTable/DataSet 920—921 objects in binary format, 902—903 UpdateInventory( ) method, 919 isolating strongly typed database code binding DataTable objects to Windows into class libraries Forms GUIs deleting data with generated codes, DataView type, 912—913 942—943 deleting rows from DataTable, 907— inserting data with generated codes, 908 941—942 hydrating DataTable from generic invoking stored procedure using List, 904—906 generated codes, 943

1621

INDEX ■

overview, 938 UpdateInventory( ) method, 919 selecting data with generated codes, discrete key frames, authoring animation 940—941 in XAML, 1311—1312 viewing generated codes, 939—940 DiscreteStringKeyFrame elements, 1312 multitabled DataSet objects and data Dispatcher class, 1135 relationships Dispatcher property, 1135 building table relationships, 924 DispatcherObject class, 1135 navigating between related tables, Display( ) method, 685 925—927 display name, 598, 599 overview, 921 Display property, 1458, 1462 prepping data adapters, 922—923 DisplayBaseClass method, 388 updating database tables, 924 DisplayCarInfo( ) method, 684 overview, 885 DisplayCompanyData( ) method, 623 programming with LINQ to DataSet DisplayDefiningAssembly( ) method, 461, types 462, 463 DataSet extensions library, 945—946 DisplayDelegateInfo( ) method, 404 obtaining LINQ-compatible DisplayFancyMessage( ) method, 133, 134 datatables, 946—947 displaying dialog boxes, 1542—1543 overview, 943—944 DisplayName property, 1093, 1094, 1104 populating new DataTables from DisplayStats( ) method, 203, 208, 237, 239, LINQ queries, 948—950 240 role of DisplayTable( ) method, 874 DataRowExtensions.Field( ) DisplayTypes( ) method, 596 Extension method, 948 disposable objects, 305—309 Windows Forms database designer Dispose( ) method, 305, 306, 307, 308, 309, tools 310, 311, 312, 833, 1550 app.config files, 932 Distinct( ) method, 509, 516 completing Windows Forms Distributed Component Object Model applications, 937 (DCOM), 1014—1015, 1019 DataGridView control, 927—932 distributed computing APIs strongly typed data adapters, 936— .NET remoting, 1016 937 COM+/Enterprise Services, 1015 strongly typed DataRows, 935 Distributed Component Object Model strongly typed DataSets, 932—934 (DCOM), 1014—1015 strongly typed DataTables, 934 Microsoft Message Queuing (MSMQ), disconnection functionality, adding to 1015—1016 AutoLotDAL.dll named pipes, sockets, and P2P, 1019 configuring data adapters using overview, 1013 SqlCommandBuilder class, 918— XML web services, 1016—1019 919 distributed system, 1013 defining initial class types, 917 div opcode, 678 GetAllInventory( ) method, 919 Divide( ) method, 394 setting version numbers, 919 *.dll assembly, 44, 1103, 1159, 1500 testing disconnected functionality, *.dll code library, 534 920—921

1622

INDEX ■

*.dll file extension, 12—13, 14, 532, 559, 663, DOM (Document Object Model), 993, 995, 1083 1011, 1388, 1389 DLL hell, 6, 577 DOM models vs. XML APIs, 995—996 *.dll module, 14 domain first programming, 962 *.dll .NET binaries, 12 Domain Name Service (DNS), 1380, 1381 [DllImport] attribute, 605 Domain Name System (DNS), 1418 DLR. See dynamic types and Dynamic DomainUnload event Language Runtime AppDomain class, 640 DNS (Domain Name Service), 1380, 1381 AppDomain type, 647 DNS (Domain Name System), 1418 DontUseCorLibDumper.dll, 1578 do keyword, 682 dot (.) prefix, 655 Dock property, 1326, 1526 dot operator, 152, 290, 302, 339, 519, 703 DockPanel class, 1138, 1162, 1326 dotNetFx40_Client_x86_x64.exe runtime DockPanel panels, 1193—1194 profile, 37 DockPanel types, 1194 dotNetFx40_Client_x86.exe setup element, 1194, 1196, 1198, program, 37 1264 dotnetfx40_full_setup.exe setup program, DOCTYPE instruction, 1383 41 document annotations, 1120 dotNetFx40_Full_x86_x64.exe runtime document controls, WPF, 1183 profile, 37 document layout managers, WPF, 1228 dotNetFx40_Full_x86.exe setup program, Document Object Model (DOM), 993, 995, 37 1011, 1388, 1389 DotNetLanguages.net, 11 Document Outline window, 1181, 1182, double arguments, 131 1295 double array, 130 Document property, 1229, 1230 double data type, 87, 96, 130, 135 document structure, HTML, 1383—1384 double value, 1240, 1261 documentation, 585—586, 1441 DoubleAnimation class, 1304 Documents API, WPF DoubleAnimation object, 1304, 1307, 1309 block elements, 1227 element, 1310 document layout managers, 1228 DoubleAnimationUsingKeyFrames class, inline elements, 1227 1304 documents, generating from arrays and DoubleAnimationUsingPath class, 1304 containers, 1004—1005 DoubleAnimationUsingPath property, Documents tab, WPF 1255 annotations, enabling, 1232—1234 DoubleClick event, 1528 overview, 1228—1229 doubles array, 130 populating FlowDocument DoWhile activity, WF 4.0, 1089 using Blend, 1230—1231 do/while loop, 117, 119, 872 using code, 1231—1232 , 537, 576 saving and loading FlowDocument, download page, Mono website, 1565 1234—1235 Download tab, Mono website, 1565 , enabling, 1232—1234 DownloadString( ) method, 768 Doing more work in Main( )! message, 734 DownloadStringAsyn( ) method, 768 DoIt( ) method, 619, 620, 622 DownloadStringCompleted event, 768

1623

INDEX ■

DragDrop event, 1528 DrawPath( ) method, 1548 DragEnter event, 1528 DrawPie( ) method, 1548 DragLeave event, 1528 DrawRectangles( ) method, 1548 DragOver event, 1528 DrawString( ) method, 1548, 1550 Draw( ) method, 242, 243, 244, 245, 246, DrawUpsideDown( ) method, 340 337, 338, 340, 341, 342 dreamCar object, 549 DrawArc( ) method, 1548 DriveInfo class, 776 DrawBeziers( ) method, 1548 DriveInfo class types, 783—784 DrawCurve( ) method, 1548 DriveInfoApp project, 784 DrawEllipse( ) method, 1548 DriveNames variable, 1098, 1099 DrawIcon( ) method, 1548 driverName field, 175 DrawIn3D( ) method, 332 Drop activity here area, 1081 DrawInBoundingBox( ) method, 340 dropdown area, 1217 Drawing class, 1258, 1271 DropDownItems property, 1516 Drawing object, 1258, 1271 Dump menu option, 659 Drawing type, 1272 dumpbin.exe file, 535 DrawingAttributes object, 1224 DumpTypeToFile( ) method, 1572 DrawingBrush duplex messaging, 1030 building using geometries, 1272—1273 Duration object, 1307 painting with, 1273—1274 Duration property, 1306, 1307, 1310 DrawingBrush class, 1258 dynamic assemblies DrawingBrush object, 1272, 1278 emitting DrawingBrush type, 1258 assembly and module set, 693—694 DrawingContext class, 1278, 1279 constructors, 696—697 DrawingContext object, 1278, 1279 HelloClass type and String Member element, 1273 variable, 695—696 DrawingGroup property, 1255 overview, 691—692 DrawingGroup type, 1271 SayHello( ) method, 697 DrawingImage, containing drawing types ModuleBuilder type, role of, 694—695 in, 1274—1275 overview, 688 DrawingImage object, 1272 System.Reflection.Emit namespace, drawings and geometries, rendering 689—690 graphical data using System.Reflection.Emit.ILGenerator, building DrawingBrush using role of, 690—691 geometries, 1272—1273 using dynamically generated assembly, containing drawing types in 697 DrawingImage, 1274—1275 dynamic data, 720 painting with DrawingBrush, 1273— dynamic keyword, 7, 10, 115, 701, 705, 706, 1274 709, 713, 714, 718 DrawingVisual class, 1135, 1277, 1278— dynamic loading, 596, 617 1279, 1282 dynamic types and Dynamic Language DrawingVisual instance, 1279 Runtime (DLR) DrawingVisual object, 1258, 1272, 1280 C# dynamic keyword DrawLine( ) method, 1548, 1550 calling members on dynamically DrawLines( ) method, 1548 declared data, 703—704

1624

INDEX ■

limitations of, 706—707 ECMA (European Computer overview, 701—702 Manufacturers Association), 1562 practical uses of, 707 web site, 654 role of Microsoft.CSharp.dll ECMA-334 specification, 38, 1562 assembly, 705 ECMA-335 specification, 38, 1562 scope of, 706 Edit Columns dialog, 988 COM interoperability , 1196, 1202 simplifying using dynamic data, edit mode, for code snippets, 63 714—718 EditingCommands class, WPF, 1202 using C# 4.0 language features, 718— EditingMode property, 1222 724 EDM. See entity without C# 4.0 language features, EdmGen.exe file, 961 722—724 *.edmx file, 958 role of DLR generating, 961—965 dynamic runtime lookup of viewing generated data, 968—970 expression trees, 709—710 element, 969 expression trees, 708 element, 968 overview, 707 edmxResourcesToEmbed subdirectory, System.Dynamic namespace, 709 970 simplifying late bound calls using element, 968 dynamic types EF. See leveraging dynamic keyword to pass EightBallClient class, 1046 arguments, 711—713 EightBallServiceMEXBehavior element, overview, 710 1043 dynamic typing, 115 Element Property tab, 1237 dynamic variable, 703 ElementName value, 1238 dynamically adding and removing elements, XAML, 1160—1161 controls, 1435—1436 Elements method, 1000 dynamically created controls, 1436—1437 Ellipse area, 1352 dynamically generated assembly, 697 ellipse button, 1097, 1106, 1107, 1230 DynamicAsmBuilder application, 691 Ellipse class, 1162, 1247, 1256 DynamicAsmBuilder project, 698 Ellipse element, 1258 DynamicCtrls, Empty Web Site, 1433 Ellipse object, 1250, 1252, 1339, 1340 DynamicCtrls website, 1437 Ellipse types, 1254, 1339 DynamicKeyword application, 701 element, 1225, 1267 tag, 1132 EllipseGeometry class, 1255 ■E EllipseGeometry object, 1255 ellipses E string format character, 84 adding to canvas, 1249—1252 E_FILENOTFOUND constant, 260 removing from canvas, 1252—1253 early binding, attributes using, 614—615 Else branch, 1110, 1111 Easton, Mark, 1561 else statement, 120 theEBook class level string variable, 768 Embed Interop Types property, 716, 718, 720, 722

1625

INDEX ■

embedding, interop metadata, 716—717 encapsulation Emit( ) method, 690, 691, 696 of classes EmitCall( ) method, 690 internal representation of emitting HTML content, 1422 properties, 202—203 EmitWriteLine( ) method, 690, 697 overview, 194 empAge field, 200 read-only and write-only properties, empBenefits object, 232 204—205 empID field, Employee class, 196 static properties, 205—206 Employee class, 195, 196, 227, 228, 229, using .NET properties, 198—200 230, 232, 234, 235, 237 using properties within class Employee object, 200, 240 definition, 200—201 Employee type, 203, 205, 233 using traditional accessors and EmployeeApp project, 195, 206, 217, 218, mutators, 195—197 226 visibility levels of properties, 204 EmployeeApp.exe assembly, 202 as pillar of OOP, 189 Employee.cs file, 195, 217, 226 End( ) method, 1035, 1069, 1421 Employee.Internal.cs file, 217, 226 EndClose( ) method, 1040 Employees project, 241 EndEdit( ) method, 893 empName field, 196, 197 EndExceptionBlock( ) method, 690 empSSN variable, 203 EndInvoke( ) method, 399, 400, 732, 733, Empty Web Site project, 1473, 1477, 1485, 734, 738, 774, 1086 1489, 1494, 1498, 1504 EndOpen( ) method, 1040 Empty Web Site template, Visual Studio, element, 1032, 1037, 1039, 1406, 1407 1043, 1046, 1050, 1051, 1052, 1054, EmpType enumeration, 144, 145, 146, 147, 1075 149 endpoints, 1037, 1051—1052, 1072 EmpType variable, 146 EndScope( ) method, 690 Enable Deleting check box, 1454 EnforceConstraints property, 888 Enable Editing check box, 1454 EngineState enumeration, viewing type Enable( ) method, 1234 metadata for, 582—583 EnableAnnotations( ) method, 1233 enlist each command object, 882 EnableClientScript property, 1458 Enqueue( ) method, 382, 383 Enabled property, 1437, 1527 EnterLogData( ) method, 131, 132 EnabledStateGroup, 1366 EntiryDataReader, 961 EnableTheming attribute, 1401 entities, 953—955 EnableTheming property, 1432 entity classes, 973 EnableViewState attribute, 1402, 1477, entity client, 956—957 1478 Entity Client Data Reader Object, 978—979 EnableViewState property, 1478 entity data model (EDM), building and enabling analyzing autoincrementing fields, 892 enhancing generated source code, 972— in-place editing, 1454 973 metadata exchange, 1043—1045 generating *.edmx file, 961—965 sorting and paging, 1453 reshaping Entity Data, 965—967 Encapsulate Field refactoring, 61

1626

INDEX ■

viewing generated *.edmx file data, Entity Set Name field, 967 968—970 Entity Set value, 967 viewing generated source code, 970— Entity SQL, querying with, 977—978 971 Entity Types folder, 965 viewing mappings, 967 EntityCommand class, 957 Entity Framework (EF) EntityConnection class, 957 AutoLotDAL Version 4.0 EntityDataReader class, 957, 961 invoking stored procedure, 985—986 EntityKey object, 974 mapping stored procedure, 980—981 EntityObject class, 956 navigation properties, 982—984, 984— EntityState property, 975 985 node, 969 overview, 979 .entrypoint directive, 662 building and analyzing entity data .entrypoint opcode, 687 model (EDM) enum attribute, 671 enhancing generated source code, enum keyword, 21, 654 972—973 enum type generating *.edmx file, 961—965 declaring variables, 146—147 reshaping Entity Data, 965—967 discovering name/value pairs of, 148— viewing generated *.edmx file data, 150 968—970 overview, 144 viewing generated source code, 970— System.Enum type, 147 971 underlying storage for, 145—146 viewing mappings, 967 enum value, 675 data binding entities to Windows enum variable, 147, 148 Forms GUIs, 986—989 EnumBuilder member, 689 programming against conceptual enumData object, 947 model Enumerable class, 513, 514, 515, 516, 517, deleting records, 974—975 520 Entity Client Data Reader Object, Enumerable methods, 503 978—979 enumerable types, building overview, 973 building iterator methods with yield querying with Entity SQL, 977—978 keyword, 346 querying with LINQ to Entities, 975— building named iterator, 347—348 977 internal representation of iterator updating records, 975 method, 348—349 role of overview, 343—345 *.edmx file, 958 Enumerable.OfType( ) method, 507 entities, 953—955 EnumerableRowCollection class, 947, 948 entity client, 956—957 Enumerable.Where( ) method, 519 object services, 956 EnumerateMachineDataWF project, 1093 ObjectContext and ObjectSet EnumerateMachineInfoWF project, 1103 classes, 958—960 enumerating contained controls, 1432— overview, 951—952 1435 Entity model, 929 enumerating files, with DirectoryInfo type, Entity Model Data Wizard, 963 780—781

1627

INDEX ■

enumeration types, Common Type System incoming, listening to, 422—423 (CTS), 21 overview, 418 enumerations, 21, 144, 145, 147, 671 registrating, simplifying event using Enum.Format( ) method, 148 Visual Studio 2010, 423—424 Enum.GetUnderlyingType( ) method, 147, Events tab, 1171, 1181, 1370 148 element, 1311 Environment class, 79, 181 Except( ) method, 515 Environment type, 80, 81 Exception base class, 272 Environment.GetCommandLineArgs( ) exception block, 690 method, 1140 Exception class, 267 ephemeral generations, 296, 297 Exception code snippet template, 277 Equal value, 1461 exception event handler, 1481—1482 equality operator, 164, 449—450, 476—478 . See structured Equals( ) method, 91, 97, 102, 251, 253, 449, exception handling 450, 476, 477 Exception object, 1101 Erase mode, 1223 Exception property, 1097 Erase Mode! value, 1218 exception-derived type, 272 EraseByStoke mode, 1223 Exchange( ) method, Interlocked class, 756 eraseRadio control, 1219 *.exe assembly, 686 Error event, 1425—1426, 1481 *.exe file extension, 12, 13, 14—15, 532, 664, error handling activities, WF 4.0, 1092— 1124 1093 *.exe module, 14 Error List window, Visual Studio 2010, 605, Execute button, 771 608 Execute( ) method, 1109 error window, Visual Studio 2010, 246 ExecuteAssembly( ) method, AppDomain ErrorMessage property, 1458, 1459 class, 638 escape characters, 100—101, 1174 Executed attribute, 1205 European Computer Manufacturers Executed events, 1203, 1205 Association (ECMA), 1562 Executed handlers, 1206 event handling, server-side, 1430 ExecuteFunction( ) method, 985 event keyword, 397, 406, 419—421 ExecuteFunction( ) method, 959 event model, WPF, 1139 ExecuteNonQuery( ) method, 859, 861, event triggers, authoring animation in 862, 863, 871, 882 XAML, 1310—1311 ExecuteReader( ) method, 834, 853, 858, EventArgs class, 1424, 1517, 1518 859, 861 EventBuilder member, 689 ExecuteScalar( ) method, 859 EventHandler delegate, generic, 426 ExecuteStoreCommand( ) method, 959 EventInfo class, System.Reflection Existing Item menu option, 1287 Namespace, 587 Exists property, FileSystemInfo class, 778 events, C# ExistsInCollection activity, WF 4.0, creating custom event arguments, 424— 1092 425 Exit event, 1128, 1129, 1136, 1137, 1147 event keyword, 419—421 Exit handler, 1130 generic EventHandler delegate, 426 Exit menu, 1516, 1523, 1538 hidden methods of, 421 Exit option, 1196

1628

INDEX ■

ExitCode property, System.Environment initial C# code, 1359 class, 81 overview, 1356 ExitEventArgs class, 1137 programmatically starting ExitEventHandler delegate, 1137 storyboard, 1363—1364 ExitTime property, System.Diagnostics. renaming initial, 1357—1358 Process class, 628 SpinControl, 1358 exitToolStripMenuItem menu, 1523 working with shapes using Expander control, 1198, 1206 brush and transformation editors, Expander widget, 1195 1269—1271 ExpenseIt WPF sample program, 1124 combining shapes, 1268 explicit attribute, 669 converting shapes to paths, 1267— explicit cast operation, 107, 249, 1107 1268 explicit conversions overview, 1266 for square types, 458 selecting shape to render from tool when required, 454 palette, 1266—1267 explicit interface implementation, 336, Expression property, DataColumn class, 337, 339, 342 890 explicit keyword, 455, 456 expression trees, 708—710 explicit load, 554 extendable applications explicitly implemented interface, 338 C# Snap-In, 619—620 explicitly pop, 679 CommonSnappableTypes.dll, 619 Exploded event, 420, 421, 428 extendable Windows Forms exponential format, 84 application, 621—624 exponential notation, 84 overview, 618 Export All button, 1276 Visual Basic Snap-In, 620 Export button, 720 extendable Windows Forms application, Export dialog box, 1276 621—624 Export menu option, 1276 ExtendedProperties collection, 898 exporting, design document to XAML, ExtendedProperties property, 887 1275—1276 extending interface types, 469—470 ExportToExcel( ) method, 720, 722 extends attribute, 655, 660, 669, 670 exposing single services using multiple extends clause, 670 bindings, 1052—1053 Extends token, 583 Expression area, 1107 Extensible Application Markup Language Expression Blend (XAML), 993 building user interface with Extensible Hypertext Markup Language key aspects of, 1207—1213 (XHTML), 1383, 1392 TabControl control, 1213—1215 Extensible Markup Language (XML), 995, establishing data bindings using, 1236— 996, 997, 998, 999, 1000, 1001, 1238 1002, 1003, 1004 extracting resources in, 1301—1303 Extensible Markup Language (XML) generating WPF styles with, 1320—1324 schema editor, 902 populating FlowDocument, 1230—1231 Extensible Markup Language Path UserControls, building custom Language (XPath), 993 animation, defining, 1359—1362

1629

INDEX ■

Extensible Markup Language Query Factory property, Task class, 766 (XQuery), 993 false branch, 1097 Extensible Markup Language Schema false operator, 445 Definition (XSD) editor, 902 false value, 330 Extensible Stylesheet Language Family FCLs (Framework class libraries), 3 Transformations (XSLT), 993 feed project template, RSS, 1024 extension libraries, 467—468 Field #n token, 583 extension methods field access, with pointers, 484 extending interface types with, 469—470 field data extension libraries, 467—468 defining in CIL, 674—675 importing types that define, 465—466 static, 182—185 IntelliSense mechanism, 466—467 .field directive, 674 invoking on instance level, 463 Field( ) method, 948 invoking statically, 464 FieldBuilder member, 689 overview, 460—462 FieldBuilder type, 696 scope of, 464—465 FieldCount property, 860 Extension property, FileSystemInfo class, FieldInfo array, 591 778 FieldInfo class, System.Reflection ExtensionMethods project, 461, 467 Namespace, 587 Extensions class, 1000 FieldModifier keyword, 1156, 1159 extern attribute, 662 fields, custom metadata viewer, 591 external assemblies FIFO (first-in, first-out), 362, 377 loading, 596 Figure class, 1230 referencing, 32 Figure element, 1227 External AssemblyReflector application, Figure type, 1227 597 File | Open menu option, 33, 35 external attribute, 666 File class, 776, 777 external code libraries, 1083 file extensions, 532 external XAML files, 1082 File menu, 1205, 1516, 1523, 1552 ExternalAssemblyReflector application, File Open dialog box, 622 596 .file token, 551 Extract Interface refactoring, 61 File Transfer Protocol (FTP), 1381, 1407 Extract Method option, 61 file types, 789—791 Extract Method refactoring, 61 file-centric methods, 790—791 Extract value to Resource option, 1293 FileExit_Click( ) method, 1197 extracting resources FileInfo class changing after, 1295 AppendText( ) method, 789 in Expression Blend, 1301—1303 Create( ) method, 786 CreateText( ) method, 789 function of, 776, 777 ■F Open( ) method, 786—788 OpenRead( ) method, 788 F string format character, 84 OpenText( ) method, 789 F suffix, 87 OpenWrite( ) method, 788 F# language, 10 overview, 785

1630

INDEX ■

File(Info) types, 777—778 finalization queue, 305 FileMode enumeration, 787 finalization reachable table, 305 FileName property, 1559 Finalize( ) method, 252, 298, 302, 303, 305, FileNotFoundException class, 260, 281 306, 310 FileNotFoundException error, 1578 finally blocks, 282, 304, 690 FileNotFoundException exception, 554, finally clause, 756 555, 569 finally keyword, 261 FileNotFoundException object, 281 FindAll( ) method, 430, 431, 432, 491 File.Open( ) method, 281, 1175 FindByCarID( ) method, 934 FilePath property, 1418 FindLongestWord( ) method, 769 files FindLongestWord( )method, 770 enumerating with DirectoryInfo type, FindMembers( ) method, System.Type 780—781 class, 588 watching programmatically, 801—804 Find/Replace dialog box, 1542 FileStream class, 776 FindTenMostCommon( ) method, 769, 770 FileStream object, 788 Finish button, 930, 1456 FileStreamApp project, 793, 794 FinishButtonClick event, 1456 FileStreams class, 793—794 First( ) method, 500 FileSystemInfo abstract base class, 777— FirstChanceException event, AppDomain 778 class, 640 FileSystemWatcher class, 776, 801, 802 first-in, first-out (FIFO), 362, 377 Fill color, 1368 FirstName property, 379, 702 Fill( ) method, 835, 914, 915, 916, 919, 937 firstName variable, 99 Fill property, 1249, 1250, 1258, 1260, 1273, FirstOrDefault( ) method, 976 1294, 1352, 1353, 1365, 1368 FirstWorkflowExampleApp project, 1079, FillBehavior property, Timeline class, 1306 1088 FillContains( ) method, 1254 fixed keywords, pinning types with, 485— FillDataSet( ) method, 891, 898 486 FillDataSetUsingSqlDataAdapter fixed pointer-centric keyword, 479 application, 914 element, 1228 FillDataSetUsingSqlDataAdapter project, fixeddocuments (WYSIWYG), 1120 917 fixed-point formatting, 84 FillEllipse( ) method, 1549, 1550 flags, 44, 535 FillPath( ) method, 1549 Flip value, 129 FillPie( ) method, 1549 Flip Y Access option, 1360 FillPolygon( ) method, 1549 float data type, 87, 154 FillRectangle( ) method, 1549 float variable, 87 FillTheseValues( ) method, 128 Floater class, 1230 filter criteria, selecting rows based on, 908— Floater element, 1227 911 Floater type, 1227 Filter property, 1559 Flop value, 129 filtering data, using OfType( ), 508 flow chart workflow, 1089 finalizable objects, 302—305 Flow Control area, 1107 FinalizableDisposableClass project, 310, flow documents, 1120 312 flowchart activities, WF 4.0, 1089—1090

1631

INDEX ■

Flowchart activity, 1090, 1093, 1094, 1107 for statement, 117 Flowchart section, Toolbox, 1093 ForAll( ) method, 771 flowchart workflows forcing garbage collection, 299—302 connecting activities in, 1094 ForEachT activity, 1099—1100 defining workflow wide variables, 1095— foreach code, 63 1096 foreach construct, 63, 343, 345, 346, 497, FlowDecision activity, 1096—1097, 1098 500 ForEachT activity, 1099—1100 foreach enumeration, 346, 1100 InvokeMethod activity, 1094—1095 foreach iteration, 906 overview, 1093 foreach keyword, 78, 118, 344, 346, 349, TerminateWorkflow activity, 1097 682, 771, 1099 FlowDecision activity, 1090, 1094, 1096— foreach logic, 502 1097, 1098 foreach loop, 118, 245, 346, 590, 594, 985 FlowDocument foreach scope, 623 loading, 1234—1235 foreach style, 362 populating, 1230—1232 foreach syntax, 346 saving, 1234—1235 ForEach activity, WF 4.0, 1089 FlowDocument container, 1231 ForEach mini designer, 1100 FlowDocument data, 1235 foreach/in loop, 117 FlowDocument object, 1228, 1234 foreach-like iteration, 368 FlowDocumentPageViewer manager, 1228 foreach-style iteration, 376 FlowDocumentReader control, 1229 ForeColor property, 1438, 1458, 1526 FlowDocumentReader manager, 1228 Foreground color, 1351 FlowDocumentReader object, 1231, 1233 Foreground property, Control Type, 1133 FlowDocumentScrollViewer manager, foreground threads, 749—750 1228, 1231 ForegroundColor property, FlowSwitch activity, 1090, 1097 System.Console class, 81 Flush( ) method Fork class, 334 BinaryWriter class, 800 Form class, 766, 1473, 1514, 1515, 1529— Stream class, 792 1530, 1538 TextWriter class, 795 Form collection, 1476 Focusable property, UIElement type, 1134 form data, accessing, 1419—1420 Focused property, 1527 form elements, 1396 FocusedStateGroup, 1366 form inheritance, 1543—1545 Font property, 1438, 1526 Form property, 1418, 1419, 1420 Font type, 1547 form statement, 1417 FontFamily property, Control Type, 1133 Form string, 1532 FontFamily type, 1547 Form type FontSize attribute, 1326 Control class, 1526—1529 FontSize property, Control Type, 1133 Form class, 1529—1530 FontStretch property, Control Type, 1133 life cycle, 1531—1533 FontWeight property, Control Type, 1133 overview, 1525 Foo( ) method, 704, 705

element, 1384, 1385, 1387, 1390, for keyword, 117, 122, 682 1397, 1403, 1442, 1448, 1449, 1478 for loop, 77, 78, 117, 682 Form1.cs file, 763, 920, 1552

1632

INDEX ■

Form1.cs icon, 1520 freachable table, 305 Format drop-down list, 1276 friend assemblies, 545 Format( ) method, String system type, 97 friendly names, mapping database names FormatException class, 260 to, 916 FormatNumericalData( ) method, 84 FriendlyName property, 639 FormattedResponse argument, 1105, 1107 from operator, 497, 510, 517, 518 FormattedResponse variable, 1108, 1111 From property, 1305, 1307, 1310 FormattedText object, 1279 FromHdc( ) method, 1548 formatters, for serialization FromHwnd( ) method, 1548 IFormatter and IRemotingFormatter FromImage( ) method, 1548 interfaces, 809—810 FTP (File Transfer Protocol), 1381, 1407 overview, 808 Full Installation option, Mono website, type fidelity among formatters, 810—811 1566 formatting, 84 FullName property, FileSystemInfo class, FormBorderStyle enumeration, 1529 778 FormBorderStyle property, 1529, 1538 fully qualified name, 31, 252, 532 FormBorderStyle.FixedDialog property, Func<> delegates, 492, 517, 518, 519, 520 1538 Func<> type, 521 FormClosed event, 989, 1531, 1532 Func delegate, 763 FormClosing event, 1531, 1532 Function Imports folder, 980 FormClosingEventArgs event, 1532 function pointer, C-style, 21 FormClosingEventArgs.Cancel property, FunWithArrays application, 144 1531 FunWithArrays project, 137 FormClosingEventHandler delegate, 1531 FunWithEnums project, 144, 150 Form.cs file, 1549 FunWithGenericCollections project, 385 form's client area, invalidating, 1551 FunWithLinqExpressions application, 509 form's default input button, setting, 1541 FunWithLinqExpressions project, 517 Forms designer, 1522, 1523 FunWithMethods application, 134 forms, HTML, 1384 FunWithMethods proyect, 126 Forms-based authentication model, 1507 FunWithPageMembers website, 1419 FormStartPosition enumeration, 1530 FunWithProfiles project, 1504 FormWindowState enumeration, 1530 FunWithStrings project, 98, 106 Fortran syntax, 12 FunWithStructures project, 151, 154 Frame class, 1124, 1155 FunWithThemes web site, 1471 Framework class libraries (FCLs), 3 FunWithThemes website, 1466 FrameworkElement class, 1117, 1248, 1271, 1278, 1280, 1281, 1282, 1292, 1327, 1329 ■G FrameworkElement type, 1133, 1134, 1272 FrameworkPropertyMetadata constructor, G string format character, 84 1329 GAC (Global Assembly Cache), 32, 51, 533, FrameworkPropertyMetadata object, 1329, 559, 560, 561, 565—566, 1022, 1414 1335 gacutil utility, Mono, 1570, 1575 FrameworkPropertyMetadataOptions gacutil.exe utility, 565, 566, 576, 1570, 1575 enum, 1329 GainFocusStar, 1366

1633

INDEX ■

Garage class, 209, 343, 346, 347 creating custom generic structures and Garage object, 210 classes, 388—392 garbage collection defining in CIL, 671—672 background (.NET 4.0), 297 generic type parameters, 371—375 concurrent (.NET 1.0 - 3.5), 297 non-generic collections, issues with forcing, 299—302 overview, 361—362 GC.Collect( ) method, 298, 299, 300, 301, performance, 363—367 302 type safety, 367—371 GCCollectionMode enumeration, 298, 300 System.Collections.Generic namespace *.g.cs file, 1150, 1165 collection initialization syntax, 378 GC.SuppressFinalize( ) method, 310 List class, 379—380 GC.WaitForPendingFinalizers( ) method, overview, 376—377 300 Queue class, 382—383 GDI+, rendering graphical data using, SortedSet class, 383—385 1545—1551 Stack class, 380—381 Graphics type, 1548—1549 geometries. See drawings and geometries invalidating form's client area, 1551 Geometry class, 1254, 1255, 1257 obtaining Graphics object with Paint Geometry objects, 1246, 1248, 1254, 1255 event, 1549—1550 Geometry property, 1255 overview, 1545—1546 Geometry type, 1257 System.Drawing namespace, 1547 GeometryDrawing class, 1246 general catch statements, 279—280 GeometryDrawing object, 1258 general exceptions, throwing, 265—266 GeometryDrawing property, 1255 Generate Asynchronous Operators check GeometryDrawing type, 1271 box, 1068 element, 1275 Generate option, 963 GeometryGroup class, 1255 generation 0 objects, 296 GeometryGroup object, 1255 generation 1 objects, 296, 297 element, 1272 generation 2 objects, 296, 297 GeometryTransform property, Shape class, generational value, 297 1248 generic List, hydrating DataTables get ( ) methods, 592 from, 904—906 get block, 204 generic members, 22 Get button, 1474 generic types, 22, 594 get directive, 676 GenericDelegate application, 415 get keyword, 204 GenericDelegate project, 418 get method, 195, 196, 198, 202 GenericPoint project, 388, 391 GET method, 1384, 1391, 1417, 1418, 1420 generics get scope, 198, 199 constraining type parameters get_ prefix, 202, 676 examples using where keyword, get_PetName( ) method, 584 393—394 get_SocialSecurityNumber( ) method, 203 lack of operator constraints, 394—395 get_XXX( ) method, 202 overview, 392 GetAllInventory( ) method, 919, 921, 1107 creating custom generic methods, 385— GetAllInventoryAsDataTable( ) method, 388 874

1634

INDEX ■

GetAllInventoryAsList( ) method, 874 GetID( ) method, 197 GetAllTracks( ) method, 314, 315 GetILGenerator( ) method, 696 GetArea( ) method, 1254 GetInterfaces( ) method, 588, 591 GetAssemblies( ) method, 638, 641 GetIntFromDatabase( ) method, 163, 164 GetBenefitCost( ) method, 232 GetInventory( ) method, 1072 GetBoolFromDatabase( ) method, 163 GetInvocationList( ) method, 402 GetChanges( ) method, 888 GetLogicalDrives( ) method, 782, 1098 GetChildren( ) method, 1342 GetMembers( ) method, System.Type GetCoffee( ) method, 382, 383 class, 588 GetColumnError( ) method, 893 GetMethods( ) method, System.Type class, GetColumnsInError( ) method, 893 588 GetCommandLineArgs( ) method, 78, 79 GetMsg( ) method, 691 GetConstructors method ( ), System.Type GetName( ) method, 197 class, 588 GetNestedTypes( ) method, System.Type GetCurrentPay( ) method, 197 class, 588 GetCurrentProcess( ) method, GetNumberOfPoints( ) method, 324 System.Diagnostics.Process class, GetObjectByKey( ) method, 959, 974, 975 629 GetObjectData( ) method, 820, 822 GetCurrentThreadId( ) method, GetParameters( ) method, 594 AppDomain class, 639 GetPerson( ) method, 368 GetDirectories( ) method, DirectoryInfo GetPetName( ) method, 67, 843 class, 778 GetPetName procedure, 869, 943 GetDomain( ) method, GetPosition( ) method, 1143 System.Threading.Thread Class, GetProcesses( ) method, 741 System.Diagnostics.Process class, GetDomainID( ) method, 629 System.Threading.Thread Class, GetProperties( ) method, System.Type 741 class, 588 GetDrives( ) method, DriveInfo class, 783 GetRandomNumber( ) method, 181, 182 GetEnumerator( ) method, 343, 344, 345, GetRenderBounds( ) method, 1254 346, 348, 349 GetSchema( ) method, 855 d__0 type, 348 GetStringArray( ) method, 142 GetEvents( ) method, System.Type class, GetStringSubset( ) method, 505 588 getter method, 194 GetFactory( ) method, Getter/Setter tokens, 584 DbProviderFactories class, 848, GetTheCars( ) method, 348 849 d__6 type, 348 GetFields( ) method, System.Type class, GetTotalMemory( ) method, System.GC 588 class, 298 GetFiles( ) method, DirectoryInfo class, GetType( ) method, 140, 147, 252, 324, 588 779, 780 GetUserAddress( ) method, 1507 GetGeneration( ) method, System.GC GetUserData( ) method, 82 class, 298 GetValue( ) method, 578, 1109, 1135, 1328, GetHashCode( ) method, 91, 251, 252, 255, 1330 476 GetValues( ) method, 148

1635

INDEX ■

GetVisualChild( ) method, 1281 graphical transformation objects, 1264 GiveBonus( ) method, 235, 236, 237, 239, Graphical User Interface (GUI), 38, 81, 903, 240 904, 1006, 1007, 1059, 1060, 1061, GivePromotion( ) method, 249, 250 1389 Glade 3 tool, Mono, 1571, 1572 Graphical User Interface Toolkit (GTK#), Global Application Class icon, 1479 1565, 1566 global application object, 1140 graphics Global Assembly Cache, 848 retained-mode, 1245 Global Assembly Cache (GAC), 32, 51, 533, vector, 1120 559, 560, 561, 565—566, 1022, 1414 Graphics class, 1549 global last-chance exception event Graphics object, obtaining with Paint handler, 1481—1482 event, 1549—1550 Global.asax file Graphics type, 1548—1549 global last-chance exception event GreaterThan value, 1461 handler, 1481—1482 *.g.resources file, 1151 HttpApplication base class, 1482 Grid class, 1138, 1160, 1162 overview, 1479—1480 Grid control, 1349 Global.asax script, 1482 Grid panels, 1186, 1191—1193 Global.asax.cs, 1485 control, 1228 element, 1427 layout manager, 1211 globally unique identifier (GUID), 351, 560, type, 1173, 1174, 1191, 1196, 1198, 889, 899 1216 GlyphRunDrawing type, 1271 Grid.Column property, 1192 -godmode option, 79 element, 1191 goto keyword, 117, 122 gridInventory, 1242 GoToState( ) method, 1367 Grid.Row property, 1192 GoToStateAction, 1367 Grid.RowDefinitions element, 1191 gradient brush, 1259, 1292 GridSplitter types, 1192—1193 gradient offset, 1259 control, 1192, 1193 gradient stop, 1259 GridView class, 1396, 1397, 1398, 1399, gradient strip, 1259 1403, 1408, 1479, 1492, 1493 Gradient Tool icon, 1269 GridView control, 1441, 1450, 1451, 1453, GradientStop objects, 1261 1454 graphical content, 1188 GridView widget, 1451 graphical data, rendering using GDI+ GridWithSplitter.xaml file, 1193 Graphics type, 1548—1549 group box, 1220 invalidating form's client area, 1551 group name, 1220 obtaining Graphics object with Paint group operator, 509 event, 1549—1550 elements, 1508 overview, 1545—1546 GroupBox class, 907, 925 System.Drawing namespace, 1547 grouping graphical layer, 1277 conceptual, 1078 graphical output, capturing and rendering, profile data, 1507—1509 1557 GroupName property, 1220 graphical systems, immediate-mode, 1245 groups, defining, 1463—1465

1636

INDEX ■

GrowLabelFont.xaml file, 1309 HeaderText property, 1462 Grunt value, 147 heap allocation, 291, 366 GTK# (Graphical User Interface Toolkit), Height attribute, 1146 1565, 1566 Height property, 1133, 1145, 1152, 1187, GUI (cache application Graphical User 1193, 1304, 1305, 1326, 1327, 1438 Interface), 1492 Height value, 1188, 1189, 1193 GUI (Graphical User Interface), 38, 81, 903, HeightProperty field, 1329 904, 1006, 1007, 1059, 1060, 1061, Helicopter class, 550 1389 helicopter.cs file, 550, 551 GUI (session application Graphical User Hello World application, 27 Interface), 1495 -HelloClass constructor, 696 GUI animation tools, 1304 HelloClass type, emitting, 695—696 GUI editor, 543 HelloMsg.cs file, 46 GUI framework, 618 HelloProgram.cs file, 658 GUID (globally unique identifier), 351, 560, HelloProgram.exe file, 659 889, 899 HelloProgram.il file, 664 GZIP standard, 1394 HelloWebService.asmx file, 1017 HelloWorld class, 691, 695, 697 HelloWorld( ) method, 1018 ■H helloWorldClass variable, 697 HelloWorldWebService project, 1019 H command, 1257 Help cursor, 1314

tag, 1386 Help Library Manager, 68 Halo8.exe application, WPF, 43 Help menu, SharpDevelop, 53 Handle property, System. Diagnostics. Help page, 68 Process class, 628 Helper class, rigging up UI to, 1009—1011 Handled property, 1339, 1341, 1537 HelpExecuted( ) method, 1204 [HandledProcessCorruptedStateException HelpLink property, 262, 268, 269—270 s] attribute, 286 [helpstring] attribute, 658 hard-code, 1236 hexadecimal formatting, 84 has-a relationship, 5, 190, 213, 219, 232, Hexagon class, 189, 191, 324, 525 806 Hexagon object, 333 HasChanges( ) method, 888 Hexagon type, 243, 328, 329 HasControls( ) method, 1432 hidden this reference, 682 HasErrors property, 888, 893 Hide( ) method, 1529 hash code, 255, 256, 560, 561 hit test operations, responding to, 1282— HashSet class, 377 1284 Hashtable class, 362, 1479 HitTest( ) method, 1283 Hashtable types, 251, 255 HitTestResult object, 1252 HasValue property, 163, 164 HitTestResultCallback delegate, 1283 HatchBrush object, 1550 Home node, 1446 header information, Windows, 534 Horizontal split button, 1170 Header property, 1214 Horizontal value, 1190 Header values, 1196 HorizontalAlignment property, Headers property, 1418 FrameworkElement type, 1133

1637

INDEX ■

HorizontalContentAlignment property, HttpApplicationState object, 1484, 1485, Control Type, 1133 1488 HorseAndBuggy class, 607 HttpApplicationState type, 1482, 1483, HorseAndBuggy type, 607 1484, 1486, 1487, 1488, 1489 element, 1039, 1043 HTTP-based bindings, 1029—1030 hosting HttpBrowserCapabilities class, 1419 services within Windows services HttpBrowserCapabilities object, 1419 creating installer, HttpCookie class, 1498 1064—1065 HttpCookie collection, 1421 enabling MEX, 1064 HttpCookie type, 1497, 1498 installing Windows service, 1066— HttpCookie.Expires property, 1498 1067 HttpMethod property, 1418 overview, 1061 HttpRequest class, 1417, 1418, 1419, 1420 specifying ABCs in code, 1062—1063 HttpRequest object, 1482 Windows Communication Foundation HttpRequest.Browser property, 1389 (WCF) services HttpRequest.Cookies property, 1498, 1499 element, HttpRequest.Form form, 1436 1042 HttpRequest.Form property, 1419 coding against ServiceHost type, HttpRequest.QueryString property, 1419 1038 HttpResponse class, 1419, 1421, 1422 enabling metadata exchange, 1043— HttpResponse object, 1482 1045 HttpResponse.Redirect( ) method, 1422 establishing ABCs within App.config HttpResponse.Write( ) method, 1422 files, 1037 HttpResponse.WriteFile( ) method, 1422 overview, 1036 HttpServerUtility object, 1417, 1482 ServiceHost type, 1040—1041 HttpServerUtility.ClearError( ) method, specifying base addresses, 1038— 1426 1040 HttpServerUtility.GetLastError( ) method, href property, 577 1426 HRESULTs, 260 HttpServerUtility.Transfer( ) method, 1422 HTML. See HyperText Markup Language HttpSessionState class, 1483, 1496—1497 HTML attributes, 1441 HttpSessionState object, 1482, 1483, 1493, HTML controls, 1441 1496, 1502 HTML tab, Visual Studio, 1384 HttpSessionState type, 1483, 1494 HTML widget, 1440 widget, 1433 tag, 1383 HyperText Markup Language (HTML) HtmlButton tag, 1440 building forms, 1386—1387 HtmlInputControl tag, 1440 document structure, 1383—1384 HtmlTable tag, 1440 forms, 1384, 1477 HTTP. See Hypertext Transfer Protocol overview, 1382 HTTP GET method, 1043 representation, 1477 HttpApplication class, 1481, 1482, 1488 requests, 1482 HttpApplication type, 1473, 1483 response, 1477, 1482 HttpApplicationState class, 1484 Visual Studio 2010 designer tools, 1384— 1386

1638

INDEX ■

widgets, 1476 Icon type, 1547 Hypertext Transfer Protocol (HTTP) IContextProperty interface, 651 overview, 1379 ICreateErrorInfo interface, 261 request/response cycle, 1380 ICustomFormatter interface, 85 requests, incoming, 1417—1420 ID attribute, 1397 response, outgoing, 1421—1423 Id member, ProcessThread type, 633 stateless protocols, 1380 ID property, 198, 200, 628, 1429, 1432 IDataAdapter interface, 828, 835 IDataAdapter type, System.Data ■I namespace, 832 IDataParameter interface, 828, 834—835 I command, 872 IDataParameter type, System.Data -i command, 566 namespace, 832 i parameter, 433 IDataReader interface, 827, 836 i variable, 682, 683 IDataReader type, System.Data tag, 1386 namespace, 832 IAdvancedDraw interface, 340 IDataReader.IsDBNull( ) method, 837 IAppFunctionality interface, 619, 620, 622 IDataRecord interface, 827, 836 IAsyncResult compatible object, 733 IDbCommand interface, 827, 834 IAsyncResult interface, 399, 734, 735, 774 IDbCommand type, System.Data IAsyncResult parameter, 732, 736, 738, 739 namespace, 832 IAsyncResult-compatible object, 732 IDbConnection interface, 321, 327, 827, IAsyncResult-compatible parameter type, 833 732 IDbConnection parameter, 837 IAutoLotService.cs file, 1072 IDbDataAdapter interface, 828 IBasicMath class, 1054 IDbDataAdapter type, System.Data IBasicMath interface, 469 namespace, 833 IBasicMath.cs file, 1057 IDbDataAdapterinterface, 835 IClassFactory interface, 7 IDbDataParameter interface, 828, 834—835 ICloneable class, 323 IDbTransaction interface, 828, 834, 878, ICloneable interface, 158, 323, 349—354, 879 362 IDbTransaction type, System.Data ICloneableExample application, 323 namespace, 833 ICloneableExample project, 324 IDE (integrated development ICollection interface, 362, 377, 378 environment), 932, 996, 1024, ICollection interface, 376, 377, 378 1025, 1379, 1381, 1382, 1386, 1396, ICommand interface, 1201, 1205 1410 IComparable interface IdealProcessor member, ProcessThread building, 354—359 type, 633 overloading comparison operators, 450 IDictionary interface, 262, 270, 362 IComparable interface, 354 IDictionary interface, 1113 IComparer interface, 143, 357—358 IDictionary interface, 376 IComparer interface, 358, 376, 383 IDispatch interface, 7, 709 IComponent interface, 1525 IDisposable class, 863, 1550 IComponentConnector interface, 1151

1639

INDEX ■

IDisposable interface, 289, 305, 306, 307, IL (Intermediate Language), 12, 13 308, 309 *.il file, modifying, 662—663 IDraw3D interface, 331, 332, 333 ilasm compiler, Mono, 1569 IDrawable interface, 339, 341, 393 ilasm utility, Mono, 1571 IDropTarget interface, 322 ilasm.exe compiler, 666 IDynamicObject interface, 709 ildasm.exe file IEightBall interface, 1033, 1046 compiling CIL code using, 663—664 IEnumerable interface, building exploring assemblies using building iterator methods with yield overview, 33 keyword, 346 viewing assembly metadata, 35 building named iterator, 347—348 viewing Common Intermediate internal representation of iterator Language (CIL) code, 34 method, 348—349 viewing type metadata, 34 overview, 343—345 ILGenerator class, 691, 696, 697 IEnumerable type, 504 ILGenerator member, 689 IEnumerable interface, 499 ILGenerator objects, 690 IEnumerable, 498, 505 ILGenerator type, 690, 696 IEnumerable class, 497, 504, 505, 506, IList interface, 362 507, 945, 948 IList interface, 376 IEnumerable enumeration, 961 Image control, 1274, 1275, 1278, 1279, IEnumerable interface, 376, 377, 500, 1286, 1289, 1358, 1359 763, 765, 1000 Image property, 1544 IEnumerable object, 507 Image type, 1547 IEnumerable variable, 499 ImageAnimator type, 1547 IEnumerator interface, building ImageBrush type, 1258 building iterator methods with yield ImageDrawing class, 1246 keyword, 346 ImageDrawing object, 1258 building named iterator, 347—348 ImageDrawing type, 1271 internal representation of iterator ImageOrderAutoDialog class, 1545 method, 348—349 ImageOrderAutoDialog.cs file, 1543 overview, 343—345 images IEnumerator interface, 376 2D vector, 1271 IErrorInfo interface, 261 programmatically loading, 1288—1289 If activity, 1089, 1107—1108, 1110 ImageSource object, 1258 if keyword, 122 ImageSource property, 1258 if scope, 250 ImageUrl image, 1448 if statement, 120, 1317 IMetadataExchange class, 1055 if/else branches, 1104 imgDisplay control, 1358 if/else statement, 119, 120 imgFirst object, 1371 if/else/then statement, 1107 imgSecond object, 1371 IFormatter interface, 809—810 imgThird object, 1371 IIS ( Information Services), 1025, immediate-mode graphical systems, 1245 1026, 1036, 1037, 1040, 1071, 1074, immutability, 103 1379, 1381, 1382 implemented interfaces, custom metadata IIS virtual directories, 1381 viewer, 591

1640

INDEX ■

implements attribute, 655, 669, 670 index operator ([]), accessing items from implements clause, 670 arrays, 439 Implements keyword, 620 indexer methods implicit cast, 248 definitions on interface types, 444 implicit conversion function of, 439 routines, 458—459 multiple dimensions, 443—444 when required, 454 overloading, 443 implicit keyword, 455, 456, 459 overview, 439—440 implicit load, 554 string values, 441—442 implicit typing, 113, 701, 702 IndexOutOfRangeException class, 260 implicitly pop, 680 IndexOutOfRangeException type, 262 implicitly sealed, 223 infrastructure, adding to MainWindow implicitly typed local arrays, 139 type, 1555 implicitly typed local variables inheritance. See also polymorphism are strongly typed data, 115 base class/derived class casting rules overview, 112—113 is keyword, 250 restrictions on, 114—115 as keyword, 249 usefulness of, 116 overview, 247—248 ImplicitlyTypedLocalVars project, 112, 117 basic mechanics of <%@Import%> directives, 1398, 1402, 1403 multiple base classes, 222 elements, 1149 overview, 219 importing sealed keyword, 222—223 Inventory.xml files, 1007—1008 specifying parent class of existing types that define, 465—466 class, 220—221 Imports area, 1105 cross-language, 549 Imports button, 1105 details of Imports editor, 1105 adding sealed class, 231—232 Imports keyword, 548 controlling base class creation with Imports statement, 548 base keyword, 228—230 in operator, 497, 509, 510, 517, 518 overview, 226—227 In32Animation class, 1304 protected keyword, 230 InArgument<> properties, 1109 multiple, with interface types, 341—342 InArgument class, 1109 overview, 219 InArgument object., 1109 pillar of OOP, 189—191 inaryFormatter class, 529 programming for Include attribute, 1149 containment/delegation, 232—235 incoming cookie data, reading, 1499 revising Visual Studio class diagrams, incoming HTTP requests 224—225 access to incoming form data, 1419— System.Object class 1420 overriding system.Object.Equals( ), IsPostBack property, 1420 254—255 obtaining brower statistics, 1419 overriding overview, 1417—1418 System.Object.GetHashCode( ), incoming parameter, 146 255—256 Increment( ) method, 756, 757

1641

INDEX ■

overriding system.Object.ToString( in-memory representation, 9 ), 254 inner exceptions, 281 overview, 250—253 innerEllipse object, 1339 testing modified person class, 257— InnerException property, 263, 281 258 in/out parameter, 871 testing your modified person class, in-place editing, enabling, 1454 256 input button, setting default, 1541 inheritance chain, 615, 1416 input parameter, 78, 871 Inheritance icon, Class Designer Toolbox, input/output (I/O), 8 66 INSERT command, 914 Inheritance Picker dialog box, 1544 Insert( ) method, 97, 365, 380, 441, 1489, Inherited Form icon, 1543 1490 Inherited property, 612 Insert request, 861 Inherits attribute, 1402, 1409 Insert Snippet option, 63 Inherits keyword, 549 Insert Standard Items option, 1522 init attribute, 681 Insert statement, 862, 863, 955, 974, 1450 Init event, 1423, 1476 InsertAuto( ) method, 863, 864, 865, 868, InitClass( ) method, 934 875, 876, 1074 InitDAD( ) method, Program class, 643 InsertCar( ) method, 1072, 1073 Initial Catalog name, 854 InsertCommand property, 914, 918, 949 initial class types, 917 Insert/Delete logic, 882 InitializeComponent( ) method, 1151, InsertNewCar( ) method, 875—876 1153, 1165, 1203, 1520, 1521, 1523, InsertNewElement( ) method, 1008 1524 installing InitializeCorrelation activity, WF 4.0, 1090 Mono, 1565—1568 InitialValue property, 1459 strongly named assemblies to GAC, Ink API controls, 1183 565—566 Ink API support types, 1183 Windows service, 1066—1067 Ink API tab, WPF InstallSqlState. file, 1502 ComboBox control, 1224—1226 installutil MathWindowsServiceHost.exe InkCanvas control, 1222—1227 command, 1066 overview, 1216 instance attribute, 675 RadioButton control, 1220—1222 instance data, 182 , 1217—1219 instance level, invoking extension ink controls, WPF, 1182—1183 methods on, 463 Ink mode, 1223 int data type, 86, 87, 92, 96, 106, 107, 108, Ink Mode! value, 1218 112, 116, 145 InkCanvas control, WPF, 1222—1227 int parameters, 106 InkCanvasEditingMode enumeration, 1223 int type, 356 inkRadio control, 1219 int variable, 107, 363, 364, 1289 inkToolbar control, 1217 intArray declaration, 138 inkToolbar node, 1217 IntCollection class, 369 inline elements, WPF, 1227 integer (0), 1335 inline menu editor, 1522, 1523 Integer data type, 135, 1479 in-memory data allocation, 183, 184

1642

INDEX ■

integrated development environment interface types vs. abstract base (IDE), 932, 996, 1024, 1025, 1379, classes, 322—325 1381, 1382, 1386, 1396, 1410 overview, 321 IntelliSense, 136, 466—467, 704 Interlocked class, 740, 756, 757 IntelliSense window, 423 Interlocked.CompareExchange( ) method, interactive graphical data, 1246 757 interface attribute, 670 Interlocked.Exchange( ) method, 757 interface implementation, 336, 337, 339, Interlocked.Increment( ) method, 757 342 Intermediate Language (IL), 12, 13 interface keyword, 20, 325 Intermediate Language Disassembler Interface member, 695 utility, 33 interface types internal data, of objects, 194 Common Type System (CTS), 20 internal keyword, 20, 125, 193, 194, 545 definitions on, 444 internal modifier, 193, 194 extending, 469—470 internal reference counter, 292 InterfaceExtensions project, 469, 470 internal representation InterfaceHierarchy application, 339 of anonymous types, 474—475 InterfaceHierarchy project, 340 of overloaded operators, 451—452 InterfaceNameClash application, 336 InternalsVisibleToAttribute class, 545 InterfaceNameClash project, 339 International Organization for interfaces Standardization (ISO), 1562 building cloneable objects, 349—354 Internet Information Services (IIS), 1025, building comparable objects, 354—359 1026, 1036, 1037, 1040, 1071, 1074, building enumerable types 1379, 1381, 1382 building iterator methods with yield Internet Protocol (IP) address, 1380, 1381, keyword, 346 1418 building named iterator, 347—348 interop assemblies, 10, 714, 717 internal representation of an interop library, 716 iterator method, 348—349 interoperability assemblies, 714, 716 overview, 343—345 interoperability data, 716 custom, defining, 325—327 interoperating, 1121 defining and implementing in CIL, 670 ( ) method, 742 designing hierarchies, 339—342 Intersect( ) method, 515 explicit implementation of, resolving Intersect<>( ) method, 509 name clashes via, 336—339 into operator, 509 generic, specifying type parameters for, intrinsic control command objects, WPF, 374—375 1201 implementing, 327—328 intVal variable, 757 invoking interface members at object Invalidate( ) method, 1246, 1529, 1551, level, 329—331 1556, 1557 as parameters, 331—333 invalidating form's client area, 1551 as return values, 333 InvalidCastException exception, 329, 365 types InvalidOperationException errors, 636 arrays of, 334 Inventories property, 959 Inventory database, 973

1643

INDEX ■

Inventory objects, 984, 989, 1242 invoking services asynchronously from Inventory property, 932, 934 clients, 1067—1069 Inventory schema, 954 invoking statically, 464 Inventory table, 840—842, 850, 853, 860, I/O (input/output), 8 861, 862, 863, 864, 865 I/O and object serialization Inventory table icon, 842 abstract stream class, 792—794 Inventory variable, 1107 BinaryWriters and BinaryReaders Inventory.aspx file, 1446, 1450 classes, 799—801 Inventory.aspx page, 1454 configuring objects for serialization InventoryDAL class, 862, 863, 864, 865, overview, 806 874, 875, 880—882 public fields, private fields, and InventoryDAL object, 863, 872 public properties, 807—808 InventoryDAL type, 867, 870, 875, 1492 serializable types, 807 InventoryDALDisconnectedGUI customizing Soap/Binary serialization application, 920 processes InventoryDALDisconnectedGUI project, overview, 818—819 921 using attributes, 823 InventoryDALDisLayer class, 917, 920, using ISerializable interface, 820— 1106 822 InventoryDALDisLayer object, 918, 921 Directory type, 782—783 InventoryDALDisLayer variable, 1106, Directory(Info) and File(Info) types, 1107 777—778 InventoryDataSet class, 932, 933, 936 DirectoryInfo type InventoryDataSet.Designer.cs file, 933 creating subdirectories with, 781— InventoryDataSet.xsd file, 933 782 InventoryDataTable class, 934, 936, 941 enumerating files with, 780—781 InventoryDataTable variable, 934 overview, 778—779 InventoryEDMConsoleApp application, DriveInfo class type, 783—784 961 file type, 789—791 InventoryEDMConsoleApp example, 979 FileInfo class InventoryEDM.Designer.cs file, 970 AppendText( ) method, 789 InventoryEDM.edmx file, 962, 968 Create( ) method, 786 InventoryEDM.edmx node, 970 CreateText( ) method, 789 InventoryRecord class, 1072, 1074 Open( ) method, 786—788 InventoryRow class, 934 OpenRead( ) method, 788 InventoryTableAdapter class, 936, 937, 940 OpenText( ) method, 789 Inventory.xlsx file, 721, 1007—1008 OpenWrite( ) method, 788 invisible brushes, 1249 overview, 785 Invoke( ) method, 398, 399, 400, 403, 602, files, watching programmatically, 801— 711, 730, 1084, 1086 804 InvokeMember( ) method, System.Type object serialization, 804—806 class, 588 overview, 775 InvokeMethod activity, 1091, 1094—1095, serialization formatters 1096, 1098, 1099 IFormatter and IRemotingFormatter invoking extension methods, 463—464 interfaces, 809—810

1644

INDEX ■

overview, 808 IService1.cs file, 1057 type fidelity among formatters, 810— IService.cs file, 1072 811 ISet interface, 376 serializing collections of objects, 816— IsEvenNumber( ) method, 431 817 isFlipped variable, 1265 serializing objects using IsFocused property, UIElement type, 1134 BinaryFormatter type, 811—813 IsGenericParameter property, serializing objects using SoapFormatter System.Type class, 588 type, 813 IsGenericTypeDefinition property, serializing objects using XmlSerializer System.Type class, 588 type, 814—816 IShape interface, 341 StreamWriters and StreamReaders IsInitiating property, 1035 classes IsInterface property, System.Type class, directly creating types, 797—798 588 overview, 794 IsMDIChildIsMDIContainer property, reading from text files, 796—797 1529 writing to text files, 795—796 IsMouseDirectlyOver property, UIElement StringWriters and StringReaders type, 1134 classes, 798—799 IsMouseOver property, 1134, 1318 System.IO namespace, 775—776 IsNestedPrivate property, System.Type IO namespace, 530 class, 588 IP (Internet Protocol) address, 1380, 1381, IsNestedPublic property, System.Type 1418 class, 588 IPointy interface, 325, 326, 327, 328, 329, IsNull( ) method, 893 330, 333, 334, 335 IsNullable property, 868 IPrintable interface, 341 ISO (International Organization for IRemotingFormatter interface, 809—810 Standardization), 1562 IronPython language, 708 IsolationLevel enumeration, 879 IronRuby language, 708 IsolationLevel property, 879 is keyword, 250, 272, 307, 330—331 IsOneWay property, 1035 is-a relationships, 189, 190, 219, 220, 228, IsPetNameNull( ) method, 935 248, 806 IsPostBack property, 1417, 1420 IsAbstract property, System.Type class, IsPrimitive property, System.Type class, 588 588 IsAlive property, 741 IsSealed property, System.Type class, 588 IsArray property, System.Type class, 588 IsSecureConnection property, 1418 IsBackground property, 741, 750 IssuesWithNon-genericCollections IsChecked property, 1220 project, 371 IsCOMObject property, System.Type class, IsTabStop property, Control Type, 1133 588 IsTerminating property, 1035 IsCompleted property, 734, 735 ISupportErrorInfo interface, 261 IsCreditRisk column, 880 IsValueType property, System.Type class, IsEnabled property, UIElement type, 1134 588 IsEnum property, System.Type class, 588 IsVisible property, UIElement type, 1134 ISerializable interface, 262, 818, 820—822 ItemArray property, 893

1645

INDEX ■

element, 1149 JavaScript language, 1389 ItemHeight value, 1189 JIT (just-in-time) compiler, 536 Items (Collection) dialog box, 1218 JIT compiler, 17, 544, 656 Items (Collection) property, 1217, 1219 Jitter, 17 Items property, 1455, 1477, 1516 Join( ) method, 742 ItemsSource collection, 1242 JpegBitmapEncoder class, 1280 ItemsSource property, 1164 *.jpg files, 763, 764 ItemWidth value, 1189 just-in-time (JIT) compiler, 536 iteration constructs JVM (Java ), 25 do/while loop, 119 -k flag, 561 foreach loop, use of var within, 118 for loop, 117 representing in CIL, 682—683 ■K while loop, 119 IterationsAndDecisions project, 117, 122 kaxaml editor, 1155, 1256, 1263, 1276, 1309 iterator methods kaxaml.exe file, 1154—1156, 1173, 1186, building with yield keyword, 346 1187, 1341 internal representation of, 348—349 key frame animations, 1304 iterators, 346 Key property, DictionaryEntry type, 271 IUnknown interface, 7 keyboard activity, 1534—1537 IValueConverter interface, data conversion keyboard events, intercepting, 1143—1144 using, 1240—1241 KeyCode property, 1537 KeyDown event, 1143, 1144, 1528, 1536, 1537 KeyEventArgs class, 1143, 1517, 1536, 1537 ■J KeyEventArgs type, 1537 Jackpot Deluxe WPF application KeyEventHandler delegate, 1536 .NET 4.0 visual states keyframes, 1360 changing using VisualStateManager KeyNotFoundException exception, 377 class, 1370 KeyPress event, 1528 overview, 1366 keys, determining which was pressed, for StarButton control, 1367—1368 1536—1537 state transition timings, 1368—1369 KeyUp event, 1134, 1143, 1528, 1536 viewing generated XAML, 1369—1370 keyword color coding, 49 extracting UserControl from drawing keywords geometry, 1365—1366 pinning types with, 485—486 finalizing, 1371—1375 XAML, 1156—1159 overview, 1364 Kill( ) method, System.Diagnostics.Process Jackpot.jpg file, 1358 class, 629, 635 jagged arrays, 141 King, Jason, 1561 JaggedMultidimensionalArray( ) method, Knife class, 334 141 Java, programming language comparison, 5 ■L Java Virtual Machine (JVM), 25 L command, 566, 872, 876

1646

INDEX ■

L suffix, 87 invoking methods with parameters, Label class, 912, 920, 925, 1241, 1396, 1397, 603—604 1399, 1403, 1404, 1408 overview, 600 Label control, 1227, 1240, 1331, 1354, 1434, System.Activator class, 601—602 1436, 1439, 1455, 1485, 1495 LateBindingApp application, 601 Label object, 1236, 1309 LateBindingWithDynamic application, 711 Label type, 1304, 1456, 1506 LateBindingWithDynamic project, 711, Label widget, 322, 1422, 1433, 1474 712

1647

INDEX ■

.NET code, 581 LineGeometry object, 1255 COM type, 581 lines consuming workflow, 1112—1114 adding to canvas, 1249—1252 of extension, 467—468 removing from canvas, 1252—1253 external code, 1083 LinkedList class, 377 isolating workflows into dedicated LinkedListNode type, 377 arguments, defining, 1105—1106 LINQ assemblies, importing, 1105 programming to DataSet types with Assign activity, 1107 DataSet extensions library, 945—946 Code activity, 1109—1111 obtaining LINQ-compatible defining project, 1103—1104 datatables, 946—947 If activity, 1107—1108 overview, 943—944 namespaces, importing, 1105 populating new DataTables from Switch activity, 1107—1108 LINQ queries, 948—950 variables, defining, 1106—1107 role of unloading, 639 DataRowExtensions.Field( ) LibraryBuild.rsp file, 1573, 1574 Extension method, 948 life cycle queries, populating new DataTables of ASP.NET Web pages from, 948—950 AutoEventWireup attribute, 1424— LINQ to DataSet term, 494 1425 LINQ to Entities, querying with, 975—977, Error event, 1425—1426 984—985 overview, 1423 LINQ to Objects of Form type, 1531—1533 applying LINQ queries to collection lifeTimeInfo string, 1532 objects lifeTimeInfo variable, 1532 accessing contained subobjects, LIFO (last-in, first-out), 362, 377 506—507 Lightning Bolt button, 1221, 1523 applying LINQ queries to lightweight class type, 151 nongeneric collections, 507—508 lightweight events, 473 filtering data using OfType( ), Limes.jpg file, 1358 508 Line class, 1247, 1256 overview, 505 line geometry, 1261 applying LINQ queries to primitive Line object, 1250, 1252 arrays Line type, 1254 extension methods, 500 element, 1267 implicitly typed local variables, 498— linear gradient, 1258 500 linear interpolation animations, 1304 overview, 496—497 LinearGradientBrush class, 1161 result set, 498 LinearGradientBrush object, 1550 role of deferred execution, 501—502 LinearGradientBrush type, 1161, 1258 role of immediate execution, 502— LineBreak class, 1230 503 LineBreak element, 1227 applying to collection objects, 508 LineBreak type, 1227 C# LINQ query operators LineGeometry class, 1255 aggregation operations, 516—517

1648

INDEX ■

basic selection syntax, 510—511 vs. DOM models, 995—996 LINQ as better Venn diagramming overview, 993—994 tool, 515—516 Visual Basic (VB) literal syntax, 996— obtaining counts using enumerable, 997 513 XML documents obtaining subsets of data, 511 building UI of LINQ to XML App, overview, 508—509 1007 projecting new data types, 512—513 defining LINQ to XML Helper class, removing duplicates, 516 1008—1009 reversing result sets, 514 importing Inventory.xml files, 1007— sorting expressions, 514 1008 internal representation of LINQ query overview, 1006 statements rigging up UI to Helper class, 1009— building query expressions using 1011 enumerable type and anonymous LINQ-compatible datatables, obtaining, methods, 520 946—947 building query expressions using LinqOverArray application, 496 enumerable type and lambda LinqOverArray project, 503 expressions, 519—520 LinqOverArrayUsingEnumerable project, building query expressions using 522 enumerable type and raw LinqOverCollections project, 505, 508 delegates, 521—522 LinqOverDataSet example, 949 building query expressions with LinqOverDataTable( ) method, 945 query operators, 518 LinqRetValues application, 504 overview, 517 LinqRetValues project, 505 LINQ specific programming constructs LinqToDataSetApp application, 946 anonymous types, 493 LinqToXmlFirstLook application, 993 extension methods, 492—493 LinqToXmlObjectModel class, 1008 implicit typing of local variables, 490 LinqToXmlWinApp application, 1007 lambda expressions, 491—492 LinqUsingEnumerable application, 518 object and collection initialization Linux operating system, executing syntax, 491 Windows Forms application overview, 489 under, 1580 returning result of LINQ query, 503—505 List block, 1231 role of LINQ, 493—495 List class, 1230 LINQ to XML List element, 1227, 1231 System.Xml.Linq namespaces, 997— List type, 1227 1002 List<> class, 370 XElement and XDocument objects List<> object, 371, 372 generating documents from arrays List collection, 906 and containers, 1004—1005 List parameter, 506 loading and parsing XML content, List object, 866 1006 List class, 371, 373, 374, 377, 379—380, overview, 1002—1003 491, 719, 763, 1074 XML APIs List container, 1004

1649

INDEX ■

List object, 952 localized assemblies, 598 List type, 373, 493, 505 LocalNullableVariables( ) method, 163 List variable, 374, 506, 671, 905, 1556, .locals directive, 657, 681 1557, 1559 LocalVarDeclarations( ) method, 89 ListBox class, 1164 Location property, 1535 ListBox control, 1224, 1225, 1319, 1431, lock keyword, synchronization using, 753— 1439, 1455, 1477, 1478 754 ListBox type, 621 Lock( ) method, HttpApplicationState ListBox web control, 1477 type, 1484, 1487 ListBoxes control, 1531 lock scope, 754 listCars variable, 905 lock statement, 757 ListControl type, 1431 lock token, 753 ListDictionary type, 363 locks, threading primitives, 729 ListFields( ) method, 591 logging support, 1078 ListInterfaces( ) method, 591 logical model, 958 ListInventory( ) method, 874 logical operators, C#, 120, 121 ListInventoryViaList( ) method, 874 logical resources, 1285 ListMethods( ) method, 590, 594, 595 logical trees, WPF, 1341—1348 listOfHandlers delegate, 406 logical view, 1341 listOfHandlers variable, 407, 418 LogicalTreeHelper class, 1342 lists Login controls, 1440 comma-delimited, 130 lollipop notation, 328 semicolon-delimited, 46 long data type, 87 literal attribute, 674 longhand notation, 718 literal floating point data, 96 longhand reflection calls, 711 Load event, 719, 989, 1409, 1420, 1423, lookless, 1341 1424, 1478, 1492, 1496, 1506 LookUpColorsForMake( ) method, 1009 Load( ) method, 554, 596, 639, 1006 LookUpPetName( ) method, 876 loaded assemblies, 641—643 looping animation, 1308—1309 Loaded event, 1173, 1174, 1278, 1288, 1289, loops. See iteration constructs 1311, 1359 loose resources, WPF LoadExternalModule( ) method, 622, 623 configuring, 1287 LoadFrom( ) method, 554, 596 including files in project, 1286—1287 loading lstTextBoxData control, 1431 assemblies, into custom application domains, 645 images programmatically, 1288—1289 ■M InkCanvas data, 1226—1227 XML content, 1006 M command, 1257 Local Area Network (LAN), 1019 MacDonald, Matthew, 1395 local variables machine.config file, 1051, 1063, 1503, 1505 accessing, C#, 429—430 MachineName class, 1031 declaring in CIL, 680—681 MachineName property, mapping parameters to in CIL, 681 System.Diagnostics.Process class, LocalBuilder member, 689 628

1650

INDEX ■

MachineName property, MainWindow.Designer.cs file, 1520, 1523 System.Environment class, 81 MainWindow.g.cs file, 1150, 1165 magic numbers, 146 MainWindowTitle property, MagicEightBallService class, 1033, 1052 System.Diagnostics.Process class, MagicEightBallServiceClient application, 629 1046 MainWindow.xaml file, 1146, 1149, 1151, MagicEightBallServiceClient project, 1048, 1165, 1173, 1174, 1294, 1366 1075 Make Into UserControl option, 1365 MagicEightBallServiceClient.exe.config Make property, 1110 file, 1050 MakeACar( ) method, 291, 292, 293 MagicEightBallServiceHost project, 1036, MakeColumn column, 934 1045, 1051 MakeNewAppDomain( ) method, 645 MagicEightBallServiceHost.exe Manage Help Settings tool, 68 application, 1059 managed attributes, 675 MagicEightBallServiceHTTP directory, , 10 1036, 1045, 1048 managed heap, 289, 291, 292, 293, 294 MagicEightBallServiceHTTPDefaultBindin managed resources, 311 gs project, 1057 ManagedThreadId property, 731 MagicEightBallServiceLib namespace, Manager class, 226, 227, 228 1036 Manager object, 229 MagicEightBallServiceLib project, 1032, Manager type, 229, 230 1036 MANIFEST assembly, 544, 712 MagicEightBallServiceLib.dll assembly, MANIFEST data, 542 1036, 1049 MANIFEST icon, 35, 542 MagicEightBallTCP project, 1050 MapPath( ) method, 1418 main menu system, 1552—1553 mapping database names to friendly Main( ) method names, 916 implementing, 872 Mapping Details window, 967, 968, 969 Program class, 34 mappings, viewing, 967 variations on, 75—76 Margin property, 1195 WPF application, 626 markup, 1119 MainControl.xaml file, 1357 markup extensions, XAML, 1163—1165 MainForm class, 905, 906, 989 markup tags, 1440 MainForm_Load( ) method, 937 MarkupExtension class, 1163 MainForm.cs file, 763, 920 massive numerical value, 96 MainMenuStrip property, 1516 master constructor, 177, 178, 179, 201 MainWindow class *.master file, 1442, 1444, 1446, 1447, 1448 adding code file for, 1165 master pages defining, 1146—1147 AdRotator widget, 1447—1448 MainWindow property, 1129, 1137 bread crumbs, establishing with MainWindow type, 1516, 1535, 1553, 1555 SiteMapPath type, 1447 MainWindow_Paint( ) method, 1549 overview, 1442—1444 MainWindow.baml file, 1151 TreeView control site navigation Logic, MainWindow.cs file, 1520, 1534, 1549, 1552 1445—1447 MainWindow.cs icon, 1520 Master property, 1450

1651

INDEX ■

<%@Master%> directive, 1443 member parameters, defining in CIL, 676— MasterPage class, 1443 677 MasterPageFile attribute, 1402, 1449 member shadowing, 245—247 MasterPageFile property, 1417 member variables, 167 MasterPage.master file, 1443 MemberInfo class, System.Reflection Math class, 181 Namespace, 587 MathClient application, 1067 members, 22, 374 MathClient project, 1070, 1075 MemberType property, MethodBase MathExtensions class, 469 object, 268 MathLib.dll code library, 43 MemberwiseClone( ) method, 252, 349, MathLibrary assembly, 574 351, 353, 354 MathLibrary project, 711 MemoryStream class, 776 MathLibrary.dll assembly, 711, 712 MemoryStream object, 1234 MathMessage delegate, 435 Menu class, 1196 MathService.cs file, 1058 Menu control, 1439, 1445, 1446 MathServiceLibrary namespace, 1057, Menu item, 1447 1058 Menu property, 1530 MathServiceLibrary project, 1057 menu systems MathServiceLibrary.dll assembly, 1062 building visually, 1522—1524 MathWindowsServiceHost project, 1062, building window frame using nested 1066, 1067 panels, 1196—1197 MathWinService.cs file, 1062

definition, 1197 MatrixTransform type, 1262 MenuItem element, 1202, 1205 Max( ) method, 516 MenuItem objects, 1196 MAX_IMAGES constant, 1289 Menus & Toolbars node, 1522 Max<>( ) method, 509 MenuStrip component, 621 Max( ) method, 500 MenuStrip control, 1522 MaxGeneration method, System.GC class, MenuStrip object, 1516 298 MenuStrip type, 1516 MaxHeight property, FrameworkElement Merge( ) method, 888 type, 1133 merged resource dictionaries, defining, MaximizeBox property, 1530, 1538 1298—1299 MaximumValue property, 1460 Message property, 109, 263, 265, 267, 273, MaxSpeed variable, 263 275, 276, 284 .maxstack directive, 662, 680 Message Transmission Optimization MaxValue property, 92, 93 Mechanism (MTOM), 1029 MaxWidth property, FrameworkElement MessageBox class, 540, 1137 type, 1133 MessageBox.Show( ) method, 663, 686, mcs compiler, Mono, 1569 746, 1349, 1532 MDI (multiple document interface) messageDetails field, 274 application, 1525 MessageToShow argument, 1084, 1085 MdiChildActive event, 1531 messaging activities, WF 4.0, 1090—1091 Media controls, WPF, 1180 metadata. See also type metadata MediaCommands class, WPF, 1201 of assemblies, 17—18 MediaPlayer type, 1272 interop, embedding, 716—717

1652

INDEX ■

tables, 494 role of AsyncCallback delegate, 736— types, 536 738 metadata exchange (MEX) role of AsyncResult class, 738 behavior configuration, 1054—1055 synchronizing calling thread, 734— enabling, 1043—1045 735 metadata viewer. See custom metadata named parameters, 133—134 viewer with no parameters, invoking, 602—603 MetaInfo window, 586 optional parameters, 131—132 method attribute, 1417 out modifier, 127—128 method group conversion, 9, 412 overloading of, 135—137 method implementation, 13 overridable, 238 method invocations, asynchronous, 22 overview, 125 Method member, 401 with parameters, invoking, 603—604 method overriding, 236 params modifier, 130—131 method parameters and return values, ref modifier, 128—129 594—595 static, 181—182 Method property, 404 MEX. See metadata exchange method scope, 186, 290, 296 MFC (C++/Microsoft Foundation Classes), method signature, 132, 1572 4 MethodAttributes.Public method, 697 MFC (Microsoft Foundation Classes), 4, 25 MethodBase object, 263, 268 mfc42.dll library, 25 MethodBase.DeclaringType property, 268 MI (multiple inheritance), with interface MethodBuilder class, 697 types, 341—342 MethodBuilder member, 689 Microsoft Expression Blend, 1119 MethodBuilder type, 690 Microsoft Foundation Classes (MFC), 4, 25 MethodInfo class, 587, 710, 711 Microsoft GAC, 1575 MethodInfo object, 602 Microsoft Intermediate Language (MSIL), MethodInfo type, 590 13 MethodInfo.Invoke( ) method, 602 Microsoft Message Queuing (MSMQ), MethodInfo.Name property, 590 1015—1016, 1019, 1020, 1023, 1028, MethodName property, 1095, 1098 1031, 1032 MethodOverloading application, 137 Microsoft namespace, 30 MethodOverloading project, 135 Microsoft SQL Server data provider, 829 methods Microsoft SQL Server Management Studio, anonymous, C#, 427, 429—430 1502 custom generic, creating, 385—388 Microsoft SQL Server Mobile data custom metadata viewer, 590 provider, 829 of DataSet types, 888 Microsoft Transaction Server (MTS), 1015 default parameter-passing behavior, Microsoft.CSharp namespace, 30 126—127 Microsoft.CSharp.dll assembly, 705 extension, 10 Microsoft.CSharp.RuntimeBinder invoking asynchronously namespace, 705 overview, 733 Microsoft.CSharp.Targets file, 1149 passing and receiving custom state Microsoft.ManagementConsole data, 738—739 namespace, 30

1653

INDEX ■

Microsoft.Office.Interop.Excel.dll Module1.vb code file, 548 assembly, 720 ModuleBuilder class, 694 Microsoft.SqlServer.Server namespace, ModuleBuilder member, 689 831 ModuleBuilder type, 694—695 Microsoft-supplied data providers, 829— ModuleBuilder.CreateType( ) method, 695 830 ModuleBuilder.SetEntryPoint( ) method, Microsoft.Win32 namespace, 30, 1183, 689 1206 module-level manifest, 537, 551 Microsoft.WinFX.targets file, 1149 modules, 14, 44, 536 MIInterfaceHierarchy application, 341 Modules property, MIInterfaceHierarchy project, 342 System.Diagnostics.Process class, MIME (Multipurpose Internet 629 Extensions), 1421 modulo statement, 433, 434 Min( ) method, 516 Monitor class, 740, 756 Min<>( ) method, 509 Monitor object, 740 MinHeight property, FrameworkElement Monitor.Enter( ) method, 756 type, 1133 Monitor.Exit( ) method, 756 MinimizeBox property, 1530, 1538 MonitoringIsEnabled property, MinimumValue property, 1460 AppDomain class, 639 MiniVan class, 220, 221, 222, 602 Monitor.Pulse( ) method, 756 MiniVan objects, 453, 602 Monitor.PulseAll( ) method, 756 MinValue property, 92, 93 monitors, threading primitives, 729 MinWidth property, FrameworkElement Monitor.Wait( ) method, 756 type, 1133 Mono Miscellaneous category, 1229 building .NET applications with MissingPrimaryKeyException exception, building console application in 832 Mono, 1576—1578 mnuFile object, 1516 building Mono code library, 1572— mnuFileExit type, 1517 1575 Model Browser window, 966, 983 building Windows Forms Client Model-View-Controller (MVC) pattern, program, 1578—1580 1395 development languages Modified value, 895 MonoDevelop IDE, 1569—1570 ModifierKeys property, 1527 working with C# compiler, 1569 modifiers, for methods development tools, Microsoft- out, 127—128 compatible params, 130—131 Mono-specific development tools, ref, 128—129 1571—1572 Modifiers property, 1537, 1543 overview, 1570 modifying application data, 1486—1487 directory structure of, 1567—1568 Module class, System.Reflection further study of, 1581—1582 Namespace, 587 obtaining and installing, 1565—1568 module option, 550 overview, 1561 module set of process, 634 scope of, 1564—1565 [module:] tag, 612 who uses, 1581

1654

INDEX ■

Mono For Windows option, MouseLeave event, 1134, 1142, 1199, 1370, 1568 1528 Mono GAC, installing assemblies into, MouseLeftButtonDown event, 1250, 1251 1575 MouseMove event, 1134, 1142, 1143, 1430, mono print, 1572 1528, 1534, 1535 Mono project, 39, 1126 MouseRightButtonDown event, 1252 Mono SDK, 1565 MouseStateGroup, 1366, 1367, 1368 MonoDevelop IDE, 666, 1569—1570 MouseUp event, 1142, 1338, 1528, 1535 monodis tool, viewing updated manifest MouseWheel event, 1528 with, 1574—1575 MoveNext( ) method, 344, 348 monodis utility, Mono, 1571 MoveTo( ) method monop tool, Mono, 1571, 1572 DirectoryInfo class, 779 Moonlight, Silverlight API, 1565 FileInfo class, 785 Motorcycle class, 173, 174, 176, 177, 178, MSBuild, 43 606, 610 msbuild.exe utility, 1148, 1149, 1150, 1151, Motorcycle object, 179 1153 mouse activity processing files with determining which button was clicked, building WPF applications using 1535—1536 code-behind files, 1166—1167 overview, 1534 building WPF applications with mouse events, intercepting, 1142—1143 XAML, 1148—1150 mouse operation, 1280 mscoree.dll library, 25, 26, 37 mouseActivity variable, 1339 mscorlib reference, 662 MouseAndKeyboardEventsApp project, [mscorlib]System.Collection.ArrayList, 677 1534, 1538 [mscorlib]System.Collections.ArrayList MouseButtonEventArgs, 1252 type, 677 MouseButtons enumeration, 1534, 1535 [mscorlib]System.Enum, 671 MouseButtons property, 1527 [mscorlib]System.ValueType, 671 MouseClick event, 1535 mscorlib.dll assembly, 22, 26, 27, 32, 361, MouseDoubleClick event, 1133, 1535 587, 590, 595, 601, 1572 MouseDown event, 1134, 1142, 1248, 1276, MSIL (Microsoft Intermediate Language), 1283, 1338, 1339, 1370, 1371, 1373 13 MouseDownStar state, 1366, 1367, 1368, MSMQ (Microsoft Message Queuing), 1369 1015—1016, 1019, 1020, 1023, 1028, MouseEnter event, 1134, 1142, 1172, 1196, 1031, 1032 1197, 1199, 1306, 1370, 1528 MSMQ-based bindings, 1031 MouseEnterStar state, 1366, 1367, 1368 MsmqIntegrationBinding class, 1031, 1032 MouseEventArgs class, 1142, 1535 element, 1031 MouseEventArgs parameter, 1534 msvbvm60.dll library, 25 MouseEventArgs type, 1517 MTOM (Message Transmission MouseExit event, 1196 Optimization Mechanism), 1029 MouseExit handler, 1197 MTS (Microsoft Transaction Server), 1015 MouseExitStar state, 1366, 1368 mul opcode, 678 MouseHover event, 1528 MulticastDelegate class, 401, 403, 412 multicasting, 22

1655

INDEX ■

multicore processors, 727 prepping data adapters, 922—923 multidimensional array, 866 updating database tables, 924 multidimensional arrays, 140—141 MultitabledDataSetApp application, 921 multi-file assemblies, 14, 536—538, 586 MultitabledDataSetApp project, 927 multifile NET assemblies, building and multithreaded and parallel programming consuming asynchronous nature of delegates airvehicles.dll file, 551—552 BeginInvoke( ) and EndInvoke( ) consuming multifile assembly, 552 methods, 732 overview, 550 overview, 731 ufo.netmodule file, 551 System.IAsyncResult interface, 732— multifile pages, compilation cycle for, 1410 733 MultifileAssembly code files, 553 brief review of .NET delegate, 729—731 multi-language, programming languages, CLR thread pool, 760—761 12 concurrency, 750—758 Multiline property, 1007 invoking methods asynchronously multiple (or zero) parameters, lambda overview, 733—735 expressions with, 435—436 passing and receiving custom state multiple base classes, 222 data, 738—739 multiple bindings, exposing single services role of AsyncCallback delegate, 736— using, 1052—1053 738 multiple conditions, 1317 role of AsyncResult class, 738 multiple dimensions, indexers with, 443— synchronizing calling thread, 734— 444 735 multiple document interface (MDI) overview, 727 application, 1525 parallel LINQ queries (PLINQ) multiple exceptions canceling, 772—774 finally blocks, 282 opting in to, 772 general catch statements, 279—280 overview, 771 inner exceptions, 281 parallel programming under .NET overview, 277—278 platform rethrowing, 280 handling cancelation request, 766— multiple inheritance (MI), with interface 767 types, 341—342 overview, 761 multiple sort orders, specifying, 357—358 role of Parallel class, 763 multiple statements, processing Task class, 765—766 arguments within, 433—434 task parallel library API, 762—763 Multiply( ) method, 96, 394 task parallelism, 768—771 Multipurpose Internet Mail Extensions understanding data parallelism, (MIME), 1421 763—766 multitabled DataSet objects and data process/appdomain/context/thread relationships relationship building table relationships, 924 overview, 727 navigating between related tables, 925— problem of concurrency, 728—729 927 role of thread synchronization, 729 overview, 921

1656

INDEX ■

programmatically creating secondary MyBrushesLibrary project, 1300 threads MyBrushes.xaml file, 1299, 1300, 1301 AutoResetEvent class, 748—749 myCar object, 291, 474, 475 foreground and background myCar reference, 291 threads, 749—750 myCars list, 506 overview, 744 MyCars.dll assembly, 532 ParameterizedThreadStart delegate, MyCompany namespace, 668 747 MyConnectionFactory project, 837, 840 ThreadStart delegate, 745—746 MyConnectionFactory.dll assembly, 840 programming with timer callbacks, MyConnectionFactory.exe application, 758—759 840 synchronization MyControls.dll library, 1159 using [Synchronization] attribute, MyCoolApp.exe application, 48 757—758 myCtrls tag, 1159 using C# lock keyword, 753—754 scope, using System.Threading.Interlocked 1333 type, 756—757 MyCustomControl namespace, 1364 using System.Threading.Monitor MyCustomControl project, 1356, 1364 type, 755—756 MyCustomControl.dll assembly, 1364 System.Threading namespace, 739—740 MyDefaultNamespace namespace, 531 System.Threading.Thread class MyDerivedClass class, 669 Name property, 743 MyDirectoryWatcher project, 804 obtaining statistics about current myDocumentReader control, 1229, 1233 thread, 742 MyDoubleConverter class, 1240 overview, 741 MyEBookReader project, 771 Priority property, 744 MyEBookReader, Windows Forms MultiThreadedPrinting project, 751, 755 application, 768 MultiThreadSharedData program, 756 MyEnum enumeration, 674 element, 1317 MyEventHandler( ) method, 427 MusicMedia enum, 570 MyExtendableApp.exe assembly, 618 mutator method, 194, 195, 196, 198, 200, MyExtensionsLibrary project, 469 206 MyExtensionsLibraryClient project, 469 Mutex class, System.Threading MyExtensionsLibrary.dll assembly, 468 namespace, 740 MyGenericDelegate, 416 MVC (Model-View-Controller) pattern, MyGenericMethods class, 388 1395 myInkCanvas control, 1222 My other string value, 104 myKeyFile.snk file, 564 My3DShapes namespace, 527, 530 myListBox listbox, 1477 MyApp class, adding code file for, 1166 MyLocalVariables( ) method, 680 MyApp.g.cs file, 1150, 1153, 1166 MyMathClass class, 214, 215 MyApp.xaml file, 1147, 1149, 1166 MyMathClass.PI constant, 215 MyAssembly.dll assembly, 691 MyPage_aspx class, 1405 MyBaseClass namespace, 668, 669 MyPaintProgram namespace, 1554 myBrush key, 1296 myPanel control, 1433 myBrush resource, 1294 MyPoint type, 155

1657

INDEX ■

MyPrivateQ queue, 1032 named pipes, 1019 myProxy.cs file, 1046 NameOfControl_NameOfEvent( ) method, MyResourceWrapper class, 303, 304, 306, 1524 310, 311, 312 namespace concept, 27 MySDWinApp solution, 51 .namespace directive, 655, 668 myShapes array, 245 namespace keyword, 525 MyShapes namespace, 525, 526, 527 Namespace property, 1034 MyShell.exe application, 43 namespaces, 27—32, 1512—1513 MySqlConnection class, 828 accessing programmatically, 30—32 myTabSystem control, 1213 custom, 525—531 MyTarget method, 417 default, of Visual Studio 2010, 531 MyTestKeyPair folder, 561 defining in CIL, 668 MyTestKeyPair.snk file, 561, 562 Microsoft root namespace, 30 myTestKeyPair.snk file, 1575 nested, 530 MyTypeViewer assembly, 595 referencing external assemblies, 32 MyTypeViewer.exe, 593 workflow, 1105 MyWordPad application, 1195 element, 1427 MyWordPad project, 1207 name/value pairs, 147, 493, 1088 MyXamlPad project, 1168, 1178 naming convention, 537 MyXamlPad.exe application, 1309 narrowing conversion, 107 MyXamlPad.exe file, 1175, 1177, 1186, narrowing operation, 106, 107 1187, 1311 NarrowingAttempt( ) method, 108 naturally dirty windows, 1551 Navigate to Event Handler menu option, ■N 1205 navigating between related tables, 925—927 N string format character, 84 Navigation node, 1439 name attribute, 577, 1037, 1054, 1505 Navigation Properties section, 982 name clashes, resolving via explicit navigation properties, using within LINQ interface implementation of, 336— to Entity queries, 984—985 339 Navigation tab, 1447 Name edit area, 1213 navigation-based applications, 1124 name field, 174, 175 navigation-based desktop program, 1124 Name keyword, 1158 NavigationCommands class, WPF, 1202 Name method, FileInfo class, 785 NavigationWindow class, 1124, 1155 name parameter, 174 NavigationWindow element, 1341 Name property ndexOutOfRangeException class, 272 Employee class, 200, 201 nested assembly attribute, 669 FileSystemInfo class, 778 nested famandassem attribute, 669 FrameworkElement type, 1133 nested family attribute, 669 System.Threading.Thread class, 743 nested famorassem attribute, 669 Name values, 511, 595 nested namespaces, creating, 530 named argument syntax, 180 nested panels, WPF, building window named arguments, 133 frame using named parameters, for methods, 133—134 finalizing UI design, 1198

1658

INDEX ■

menu system, 1196—1197 CIL (common intermediate MouseEnter event handler, language) code, type metadata, implementing, 1199 and assembly manifest, 536 MouseLeave event handler, CLR file header, 535 implementing, 1199 optional assembly resources, 536 overview, 1195 overview, 533 spell checking logic, implementing, single-file and multifile assemblies, 1200 536—538 StatusBar, 1198 Windows file header, 534—535 ToolBar, 1197—1198 multifile, building and consuming nested private attribute, 669 airvehicles.dll file, 551—552 nested public attribute, 669 consuming multifile assembly, 552 nested type definitions, 233—235 overview, 550 Nested Types node, InventoryDataSet ufo.netmodule file, 551 icon, 934 private NestedAssembly member, 695 configuration files and Visual Studio NestedFamAndAssem member, 695 2010, 556—558 NestedFamily member, 695 configuring private assemblies, 554— NestedFamORAssem member, 695 556 NestedPrivate member, 695 identity of private assembly, 553 NestedPublic member, 695 probing process, 553—554 .NET 4.0 visual states publisher policy assemblies, 574—575 changing using VisualStateManager role of, 532—533 class, 1370 shared overview, 1366 configuring, 569—574 for StarButton control, 1367—1368 consuming, 567—569 state transition timings, 1368—1369 generating strong names at viewing generated XAML, 1369—1370 command line, 561—563 .NET assemblies generating strong names using element, 576—577 Visual Studio 2010, 563—564 building with CIL installing strongly named building CILCarClient.exe, 686—687 assemblies to GAC, 565—566 building CILCars.dll, 683—686 overview, 558—559 defining custom namespaces strong names, overview, 560—561 creating nested namespaces, 530 viewing .NET 4.0 GAC using default namespace of Visual Studio Windows Explorer, 566 2010, 531 single-file assembly, building and overview, 525—526 consuming resolving name clashes with aliases, building C# client application, 545— 528—530 547 resolving name clashes with fully building Visual Basic client qualified names, 527—528 application, 547—549 format of CIL (common intermediate language), 544

1659

INDEX ■

cross-language inheritance in .NET-aware programming languages, 10— action, 549 12 manifest, 541—544 *.netmodule file extension, 537, 548, 550, overview, 538—540 586 type metadata, 544—545 NetMsmqBinding class, 1031, 1032 System.Configuration namespace, 577 netMsmqBinding class, 1042 transforming markup into element, 1031 BAML, 1151—1152 NetNamedPipeBinding class, 1030, 1032 mapping application data to C# element, 1030 code, 1153 NetPeerTcpBinding class, 1030, 1032 mapping window data to C# code, element, 1030 1150—1151 NetTcpBinding class, 1030, 1032, 1049, XAML-to-assembly process, 1153— 1054, 1070 1154 NetTcpBinding object, 1050 .NET attributes element, 1030, 1050 applying in C#, 606—607 New button, 1229 attribute consumers, 605—606 New Connection button, 929, 963 C# attribute shorthand notation, 607— new( ) constraint, 393 608 New Data Source option, 1447 obsolete attribute, 608—609 option, 1172 overview, 604 New Folder menu option, 1286 specifying constructor parameters for, new instance, 253 608 new keyword, 89, 90, 125, 153, 170, 171, .NET exception handling, 260—262 209, 291, 292—293, 588 .NET executable program, process entry new object pointer, 292 point, 626 new operator, and system data types, 89— .NET Framework 4.0 SDK documentation, 90 282, 299, 307, 530, 545, 740, 756, New option, 563 773, 1184, 1336 New Project button, 1207 .NET Framework 4.0 Software New Project dialog box, 51, 56, 621, 1024, Development Kit (SDK), 41—42, 67— 1057, 1079, 1103, 1207 69 New project menu command, 1207, 1356 .NET module, 536 New Project menu option, 538, 1300, 1518 .NET platform, parallel programming New Solution menu option, 665 under New Storyboard button, 1359 data parallelism, 763—766 New Web Site dialog box Visual Studio handling cancelation request, 766—767 2010, 1025 overview, 761 newarr opcode, 678 role of Parallel class, 763 NewCar class, 864 Task class, 765—766 NewCar object, 876 task parallel library API, 762—763 NewCarDialog.cs file, 719 task parallelism, 768—771 NewCarDialog.designer.cs file, 719 .NET properties, using for encapsulation of NewCarDialog.resx file, 719 classes, 198—200 NewLine member, TextWriter class, 795 .NET remoting, 1016

1660

INDEX ■

NewLine property, System.Environment NullableTypes project, 162 class, 81 NullReferenceException, 407 newobj instruction, 292 numb1 value, 106 newobj opcode, 678 numb2 value, 106 newVersion attribute, 573 numerical conversions, 454 Next button, 928 numerical data types, 92, 127 next object pointer, 292 numerical formatting, 84 NextResult( ) method, 861 numerical value, 96, 298 ngen.exe command-line tool, 17 ngen.exe utility, Microsoft .NET, 1570 nheritance chain, 1326 ■O Nodes method, 1000 nonabstract, 1145 obj variable, 602 None radio button, 981 object (logical) resources, WPF non-ephemeral generation, 297 {DynamicResource} markup extension, non-generic collections 1295—1296 applying LINQ queries to, 507—508 {StaticResource} markup extension, issues with 1294 overview, 361—362 application-level resources, 1296—1297 performance, 363—367 changing after extraction, 1295 type safety, 367—371 extracting in Expression Blend, 1301— nonnullable variable, 162 1303 non-optional parameters, 132 merged resource dictionaries, defining, [NonSerialized] attribute, 605, 606 1298—1299 nonstatic class data, 182 resource-only assembly, defining, nonstatic method, 182, 188 1300—1301 NoNullAllowedException exception, 832 Resources property, 1292 not opcode, 678 window-wide resources, defining, not System.Int32, 366 1292—1294 Notepad++, building C# applications with, object argument, 1335 49—50 Object Browser utility, Visual Studio 2010, NotEqual value, 1461 60, 223, 1247, 1404 Nothing value, 1107 Object class, 189, 251, 252, 1137, 1416, NotPublic member, 695 1424 notserialized token, 606 object construction, parameterized, 4 Now property, DateTime class, 132 object context boundaries null brush, 1259 context-agile and context-bound types, null reference, 209, 254, 293, 330 649 null, setting object references to, 293—294 defining context-bound object, 649—650 nullable types inspecting object's context, 650—651 ?? operator, 164—165 overview, 648 overview, 162 object data type, 87 working with, 163—164 object generations, 296—297 Nullable structure type, 163 object graphs, 294, 295, 805—806 NullableTypes application, 165 object initializer syntax

1661

INDEX ■

calling custom constructors with, 212— ObjectInitializers application, 211 213 ObjectInitilizers project, 214 inner types, 213—214 object-oriented layer, 4 overview, 210—211 object-oriented programming (OOP) object instance, 194 overview, 188 object keyword, 251 pillars of object lifetime encapsulation, 189 and application roots, 294—295 inheritance, 189—191 classes, defined, 289—290 polymorphism, 191—192 disposable and finalizable blended ObjectOverrides application, 252 technique, 309—312 ObjectOverrides namespace, 253 disposable objects, 305—309 ObjectOverrides project, 253, 257 finalizable and disposable blended ObjectParameter object, 986 technique, 309—312 ObjectParameter type, 986 finalizable objects, 302—305 ObjectQuery object, 976 garbage collection, 297—302 ObjectResourcesApp application, 1292 lazy objects, 313—317 ObjectResourcesApp project, 1300, 1301, and new keyword, 292—293 1303 object generations, 296—297 objects object references, setting to null, 293— 2D geometric, 1246 294 adding to DataTable types, 892—893 objects, defined, 289—290 allocation onto managed heap, 293 overview, 291—294 arrays of, 139—140 references, defined, 289—290 command, 834 System.GC type, 298—302 connection, 833 object model disposable, 311, 312 Excel, 721 transaction, 834 , 718 unreachable, 291 Microsoft Office Excel, 715 urgency level of, 298 Object option, 987 Objects and Timeline editor, 1213, 1215, object parameters, 386, 399, 1139, 1337, 1217, 1222, 1229, 1236, 1359, 1360, 1536 1361, 1365 object references, setting to null, 293—294 Objects window, 1270 object resources, 1285 ObjectSet collection, 977 object serialization. See I/O and object ObjectSet data member, 971 serialization ObjectSet field, 974 object services, 956 ObjectSet variable, 960 Object type, 513 ObjectSet member, 959 object user, 306 ObjectSet variable, 959 object variable, 196, 365, 702 ObjectSet classe, 958—960 ObjectContext class, 958—960, 967, 970, ObjectSet field, 975 971, 973, 974 ObjectSet property, 967 ObjectIDGenerator type, ObjectSet variables, 967, 971 System.Runtime.Serialization obsolete attribute, 608—609 namespace, 818 [Obsolete] attribute, 605, 607, 608, 609

1662

INDEX ■

ObsoleteAttribute class, 607 mapping parameters to local variables ObtainAnswerToQuestion( ) method, 1035, in CIL, 681 1059 overview, 677—679 ObtainVehicleDelegate delegate, 415 representing iteration constructs in Octagon class, 337 CIL, 682—683 Octagon object, 337 role of CIL, 655 Octagon type, 337 OpCodes class, 696 ODBC data provider, 829, 830 OpCodes member, 689 OdbcConnection class, 828 Open command, WPF, 1204—1206 OdbcConnection object, 321 Open member, FileMode enumeration, OdbcDataAdapter class, 913 787 OfType( ) method, 507, 508 Open( ) method, 189, 322, 785, 786—788, oldVersion attribute, 573, 574 855, 1040, 1051 OLE DB data provider, 829, 830 OpenConnection( ) method, 863 on operator, 509 OpenFileDialog dialog box, 1183 On prefix, 1528 OpenFileDialog type, 1559 OnCarEngineEvent( ) method, 408 OpenOrCreate member, FileMode OnCarNicknameChanged( ) method, 972 enumeration, 787 OnCarNicknameChanging( ) method, 972 OpenRead( ) method, FileInfo class, 785, OnClick attribute, 1389, 1398, 1409 788 [OnDeserialized] attribute, 818 OpenText( ) method, FileInfo class, 785, [OnDeserializing] attribute, 818 789 OnDragDrop( ) method, 322 OpenTimeout property, 1040, 1053 OnDragEnter( ) method, 322 OpenWrite( ) method, FileInfo class, 785, OnDragLeave( ) method, 322 788 OnDragOver( ) method, 322 operation codes, 655 OnKeyUp event, 1528 operational contracts, service types as, OnMouseMove event, 1528 1035—1036 OnPaint event, 1528 OperationCanceledException error, 767 OnPaint( ) method, 1245 [OperationContract] attribute, 1027, 1033, [OnSerialized] attribute, 819 1034, 1035, 1073 [OnSerializing] attribute, 819 operations, Venn diagramming, 1268 OnStart( ) method, 1062 operator keyword, 654 OnStop( ) method, 1062 operator overloading OnTransformDirty( ) method, 1329 += and -+, 448 OnZipCodeLookup( ) method, 473 binary, 445—447 OO wrapper, 599 comparison, 450 OOP. See object-oriented programming equality, 449—450 Opacity property, 1307, 1521, 1527 internal representation of, 451—452 opcodes overview, 444 .maxstack directive, 680 unary, 448—449 declaring local variables in CIL, 680— Operator property, 1461 681 optional arguments, 131, 133, 134 hidden this reference, 682 optional parameters, for methods, 131—132 [OptionalField] attribute, 819

1663

INDEX ■

or opcode, 678 output variables, 127 or zero (multiple) parameters, lambda OutputStream property, 1421 expressions with, 435—436 overflow checking, 110—111 OracleConnection class, 828 overflow condition, 109 OracleConnection object, 321 OverloadedOps project, 453 Order Automobile menu, 1538 overloading methods, 135—137, 443 OrderAutoDialog class, 1544, 1545 overloading operators OrderAutoDialog object, 1542 += and -+, 448 OrderAutoDialog.cs file, 1538 binary, 445—447 OrderAutoDialog.Designer.cs file, 1543 comparison, 450 OrderBy( ) method, 519, 520 equality, 449—450 orderby operator, 497, 509, 514, 517, 518 internal representation of, 451—452 OrderedEnumerable type, 519 overview, 444 OrderedEnumerable unary, 448—449 type, 498 overridable methods, 238 OrderedEnumerable`2, 498 override keyword, 236—238, 246, 303, 549 OrderID values, 844, 845 Orders column, 988 Orders property, 959 ■P Orders table, 840, 844, 845, 846, 921, 939, 979, 984 P command, 872, 876 Ordinal property, DataColumn class, 891

tag, 1386 Orientation property, 1189, 1190, 1263 P2P (peer-to-peer) services, 1019 Original value, 896 pacing of animation, controlling, 1307— OSVersion property, 1163 1308 Other Windows menu option, 840, 965, Padding property, 1133, 1195 1181 PadLeft( ) method, String system type, 97 out argument, 400 PadRight( ) method, String system type, 97 out keyword, 127 Page class, 1124, 1144, 1155, 1379, 1406, out modifier, 127—128, 159 1411, 1416, 1417, 1421, 1423 out parameter, 400, 429 Page element, 1341 [out] token, 677 page level themes, applying, 1469 outer variables, 429 Page objects, 1124, 1125, 1155, 1450, 1474 outerEllipse control, 1338 Page property, 1432 outerEllipse object, 1339 Page type, inheritance chain of, 1416 outgoing HTTP response, 1421—1423 Page_Load event, 1493 emitting HTML content, 1422 Page_Load( ) method, 1434, 1493 redirecting users, 1422—1423 Page_NameOfEvent method, 1424 output argument, 1105 Page_PreInit( ) method, 1470, 1471 output, formatting for System.Console control, 1155 class, 83—85 definition, 1163 output parameters, 127, 128, 129, 843, 871, element, 1149, 1155, 1156, 1164 1103 scope, 1276 Output property, 1421 Pages control, 1292 Output Type setting, 1144 element, 1468

1664

INDEX ■

paging, enabling, 1453 Parallel.For( ) method, 763, 766 Paint event, 1245, 1528, 1529, 1549—1550, Parallel.ForEach( ) method, 763, 765, 766, 1555, 1556, 1557 767 PaintEventApp project, 1549, 1551 ParallelForEach activity, WF 4.0, 1089 PaintEventArgs class, 1518 Parallel.Invoke( ) method, 768, 771 PaintEventArgs parameter, 1549, 1550 ParallelOptions object, 766, 767 PaintEventHandler delegate, 1549 parameter arrays, 9, 130 Panel class, 1433 parameter modifiers, 126, 159 Panel control, 1433, 1436 Parameter object, 828 Panel object, 1463 parameter values, 133 Panel type, 1184, 1433 ParameterBuilder member, 689 Panel widget, 1436 ParameterInfo class, System.Reflection PanelMarkup folder, 1186 Namespace, 587 panels, WPF parameterized command objects, 867—869 enabling scrolling for, 1194—1195 parameterized object construction, 4 nested, building window frame using parameterized queries, 867 finalizing UI design, 1198 ParameterizedThreadStart delegate, 740, menu system, 1196—1197 744, 745, 747, 750 MouseEnter/MouseLeave event ParameterName property, 868, 869 handlers, implementing, 1199 parameters. See also type parameters overview, 1195 interfaces as, 331—333 spell checking logic, implementing, for methods 1200 default passing behavior, 126—127 StatusBar, 1198 named, 133—134 ToolBar, 1197—1198 optional, 131—132 overview, 1184—1185 specifying using DbParameter type, positioning content within 867—869 Canvas panels, 1186—1188 type, 372 DockPanel panels, 1193—1194 Parameters member, 858 Grid panels, 1191—1193 Parameters property, 834 StackPanel panels, 1190—1191 params argument, 131 WrapPanel panels, 1188—1190 params keyword, 130, 400, 676 Paragraph block, 1230, 1231 params modifier, for methods, 130—131 Paragraph class, 1230 parent class, of existing class, 220—221 Paragraph element, 1227, 1231 Parent member, DirectoryInfo class, 779 Paragraph type, 1227 Parent property, 1432 element, 1227 parent/child relationships, 190 Parallel activity, WF 4.0, 1089 ParentRelations member, 897 Parallel class, 763, 771 Parse( ) method, 96, 1006 Parallel Language Integrated Query ParseFromStrings( ) method, 94 (PLINQ), 494, 762, 771—774, 1010 parsing XML content, 1006 parallel programming. See multithreaded partial class types, 217—218 and parallel programming partial keyword, 9, 217, 218, 471, 472, 972 parallel programming library, 761 partial methods, 470—473 ParallelEnumerable class, 771 partial rollback, 879

1665

INDEX ■

PartialMethods project, 471, 473 Person objects, 159, 253, 368, 371, 373, 379, partitions, of ECMA-335, 38, 1563 380, 385, 442, 493 PasswordBox control, 1227 person only collection, 368 Paste command, 1200 Person type, 160 Path class, 776, 1247, 1253, 1254, 1255, PersonCollection class, 368 1257, 1271 PetName column, 170, 892, 910, 916 Path definition, 1267 PetName property, 242, 247, 506, 549, 966 Path menu, 1268 PetName string, 66 Path objects, 1256, 1257, 1268, 1276, 1365, PetNameComparer class, 359 1366 peverify.exe file, 666, 672, 687 Path settings, 1273 PHP applications, 1475 PATH variable, 42 physical model, 958 element, 1256 PI constant, 216 path-based animations, 1304 PIAs (Primary Interop Assemblies), 715 PathGeometry class, 1255, 1256 Pick activity, WF 4.0, 1089 PathGeometry property, 1255 Pick Color menu option, 1556 paths, 1254—1257, 1267—1268 Pick Your Color link, 1455 PathSegment class, 1257 PickBranch activity, WF 4.0, 1089 PathSegment type, 1257 PictureBox control, 1544 Patient Details button, 1122 PID (process identifier), 625, 631 Pause( ) method, 313 pinning types, with fixed keywords, 485— Pay property, Employee class, 200 486 Peek( ) method, 381, 382, 383, 796 PInvoke (Platform Invocation Services), PeekChar( ) method, BinaryReader class, 303 800 Place code in separate file checkbox, 1407 peer-to-peer (P2P) services, 1019 placeholder parameter, 373, 867 Pen button, 1365 placeholder value, 84 Pen class, 1261 placeholders, 9, 83, 135, 372, 375, 1393 Pen object, 1262, 1273, 1550 Platform Invocation Services (PInvoke), Pen tool, 1266, 1267 303 Pen type, 1547 platform-independent, nature of .NET, 37— Pencil control, 1365 39, 1561—1565 Pencil tool, 1266, 1267, 1365 platform-independent .NET development. pens, configuring, 1261—1262 See Mono Pens type, 1547 Play( ) method, 313 PeopleCollection class, 440 PLINQ (Parallel Language Integrated performance issues, non-generic Query), 494, 762, 771—774, 1010 collections, 363—367 PLINQDataProcessingWithCancellation PerformanceCar.vb file, 549 application, 771 Persist activity, WF 4.0, 1091 PLINQDataProcessingWithCancellation persistence support, 1078 project, 773 persistent cookie, 1498 plug-ins, Silverlight, 1126 persisting custom objects, 1507—1509 plus (+) operator, 23, 99, 100, 1094 Person class, 158, 159, 160, 254, 256, 367, plus token (+), 589 382, 702 Point class

1666

INDEX ■

overloading binary operators, 445, 446, overview, 235 448 pillar of OOP, 191—192 overloading comparison operators, 450 polymorphic interface, 241—245 overloading equality operators, 449 virtual keyword, 236—238 overloading unary operators, 448 virtual members, 238—239 Point objects, 211, 378, 491 Pop( ) method, 380, 381 point of no return, 1091 pop opcode, 679 Point structure, 151, 153, 155, 156, 388 PopulateDocument( ) method, 1231 Point type, 152, 212, 213, 1143, 1547 populating controls collection, 1515—1517 Point variable, 152, 153, 211 populating new DataTables from LINQ PointAnimationUsingKeyFrames class, queries, 948—950 1304 Port value, 1031 PointAnimationUsingPath class, 1304 Portable.NET, 39 PointColor enum, 212 elements, 1034 PointDescription type, 351 Position member, Stream class, 793 PointDescription variable, 351 positional parameters, 134 pointer types POST method, 1384, 1391, 1417, 1418, 1420 * and & operators, 482 posting back to Web servers, 1390—1391 field access with pointers ( -> operator), precious items, 305 484 Predicate delegate, 432 overview, 479—480 Predicate object, 430 pinning types with fixed keywords, 485— PreInit event, 1423, 1450, 1471 486 pre-JIT, 17 sizeof keyword, 486 Prepare( ) method, 859 stackalloc keyword, 485 prepared query, 859 unsafe (and safe) swap function, 483 PreRender event, 1424 unsafe keyword, 481—482 PresentationCore.dll assembly, 1127, 1135, PointF type, 1547 1157, 1168, 1183, 1271, 1304 PointRef class, 155, 156 PresentationFramework.dll assembly, Points property, 327, 329, 1253 1127, 1135, 1146, 1157, 1168, 1180, PointyTestClass project, 335 1183, 1232, 1247, 1346 policies, 1021, 1022 Preview suffix, 1339 Polygon class, 1247, 1253 PreviewKeyDown event, 1341 Polygon object, 1349 PreviewMouseDoubleClick event, Control Polygon type, 1253, 1254 type, 1133 Polyline class, 1247, 1253, 1261 PreviewMouseDown event, 1339 Polyline type, 1253, 1254 PrimAndProperCarEvents project, 426, polylines and polygons, 1253—1254 427, 436 polymorphic behavior, 22 Primary Interop Assemblies (PIAs), 715 polymorphic fabric, 618 primary module, 14 polymorphic interface, 191, 241, 323, 619 primary namespace, 1157 polymorphism. See also inheritance primary thread, 626 abstract classes, 240 PrimaryKey member, 897 member shadowing, 245—247 PrimaryKey property, 898 override keyword, 236—238 primitive arrays, applying LINQ queries to

1667

INDEX ■

extension methods, 500 configuring private assemblies, 554—556 implicitly typed local variables, 498—500 identity of private assembly, 553 overview, 496—497 probing process, 553—554 result set, 498 private object member variable, 753 role of deferred execution, 501—502 private points of data, 207 role of immediate execution, 502—503 private static object member variable, 754 primitives activities, WF 4.0, 1091 privatePath attribute, 555, 556 Primitives area, 1107 element, 569, 576 Primitives section, 1080 Pro WF: Windows Workflow in .NET 4.0, PrintArray( ) method, 142 1077 PrintCustomerOrders( ) method, 985 element, 555 PrintDataSet( ) method, 898, 900, 906, 915, process identifier (PID), 625, 631 916 Process type, System.Diagnostics PrintDocument( ) method, 17 namespace, 628 Printer class, 745, 751, 757, 760 ProcessCreditRisk( ) method, 880, 882 Printer instance, 751 processes Printer object, 751 interacting with under .NET platform Printer.PrintNumbers( ) method, 750 controlling process startup using printf( ) method, 83 ProcessStartInfo class, 636—637 PrintInventory( ) method, 941 enumerating running processes, 630 PrintMessage( ) method, 657 investigating process's module set, PrintNumbers( ) method, 745, 751, 752, 634 754, 760 investigating process's thread set, PrintState( ) method, 168, 169 631—634 PrintTable( ) method, 900 investigating specific process, 631 PrintTime( ) method, 759 overview, 627—629 Priority property, starting and stopping processes System.Threading.Thread class, programmatically, 635—636 741, 744 role of Windows process, 626—627, 652 PriorityLevel member, ProcessThread Processes tab, Windows type, 633 utility, 625 private assembly, 533, 547 ProcessExit event, AppDomain class, 640 private attribute, 669 ProcessExit event, AppDomain type, 647 private backing field, 207 ProcessFiles( ) method, 764, 766 private data, 152, 195 Process.GetProcessById( ) method, 631 private fields, 807—808 Process.GetProcesses( ) method, 630 private key data, 561 ProcessIntData( ) method, 773 private keys, 560 ProcessManipulator application, 630 private keyword, 188, 189, 193, 194, 196, ProcessModule type, System.Diagnostic 233 namespace, 628 private method, 753 ProcessModuleCollection type, private modifier, 192, 194 System.Diagnostic namespace, private .NET assemblies 628 configuration files and Visual Studio ProcessMultipleExceptions project, 277 2010, 556—558

1668

INDEX ■

ProcessNameproperty,System.Diagnostics comparison of .Process class, 629 .NET, 6—7 ProcessorAffinity member, ProcessThread C++/Microsoft Foundation Classes type, 633 (MFC), 4 ProcessorCount property, 1163 Component Object Model (COM), processors, multicore, 727 5—6 ProcessStartInfo class, controlling process C/Windows application startup using, 636—637 programming interface (API), 4 ProcessStartInfo type, System.Diagnostic Java, 5 namespace, 628 overview, 3 ProcessThread type, System.Diagnostic Visual Basic 6.0, 4 namespace, 628 programming logic, 1147 ProcessThreadCollection type, Project menu, 1018, 1298, 1331, 1538 System.Diagnostic namespace, Project node, 225 628 Project Properties editor, Visual Studio ProductInfo objects, 509 2010, 74 ProductInfo[] parameter, 511, 512, 514 Project Properties, viewing with Solution production-ready assemblies, 1562 Explorer Utility, 58 Profile API Project Properties window, 58 accessing profile data project templates, 1023—1025, 1071—1073 programmatically, 1505—1507 Project window, 1321 ASPNETDB.mdf database, 1503—1504 Projects menu option, 1207 defining user profiles within Projects tab, 1207, 1357 Web.config, 1504—1505 Project/Solution menu option, 1242 grouping profile data and persisting propdp code snippet, 1333, 1334 custom objects, 1507—1509 properties overview, 1502 automatic profile data and default values, 208—210 accessing programmatically, 1505—1507 interacting with, 208 grouping, 1507—1509 overview, 206—207 Profile property, 1504, 1506, 1508 custom, 358 element, 1504 custom metadata viewer, 591 Profile.Address group, 1507 defining in CIL, 676 ProfileCommon type, 1508 and encapsulation of classes Program class, 1521—1522 .NET, 198—200 Program type, 107, 155, 660 within class definition, 200—201 Program.cs file, 73, 507, 712, 1083, 1086, internal representation of, 202—203 1112, 1513 read-only and write-only, 204—205 programmatic idiom, 23 static, 205—206 programmatically assigning themes, 1469— visibility levels of, 204 1471 Properties editor, 543, 565, 940, 1211, 1214, programmatically watching files, 801—804 1218, 1236, 1350, 1360, 1361 value, 132 Properties icon programming languages Solution Explorer, 58, 613 .NET-aware, 10—12 Visual Studio 2010, 79

1669

INDEX ■

Properties list box, 1237 public key token, 569, 573 Properties node, 543, 562, 919 public key value, 532 Properties page, 563 public keys, 560 Properties property, 1129, 1139 public keyword, 20, 125, 152, 193, 194, Properties tab, 1208 1543 Properties window public methods, 196, 695, 753 SharpDevelop, 52 public modifier, 192, 193, 194 Solution Explorer, 1008 public point of data, 199 Visual Studio 2010, 849, 966, 1095, 1106, public properties, 152, 807—808 1250, 1287, 1385, 1386, 1429, 1526 public read-only field, 195 scope, 1508 PublicDelegateProblem project, 419 .property directive, 676 publicKeyToken attribute, 577 -Property suffix, 1242 .publickeytoken directive, 542 property syntax, automatic, 207 .publickeytoken instruction, 542 property values, setting, 10 .publickeytoken tag, 569 PropertyBuilder ( ) method, 689, 696 publicKeyToken values, 566, 577, 599 PropertyChangedCallback delegate, 1329 PublicKeyToken=null convention, 598 PropertyChangedCallback object, 1335 public/private key data, 560, 561 PropertyCollection object, 887 publisher policy assemblies, 574—575 property-element syntax, XAML, 1132, element, 575 1161, 1260 Push( ) method, 380 element, 1149 PropertyInfo class, System.Reflection Namespace, 587 ■Q PropertyInfo.GetValue( ) method, 617 property/value pairs, 1312 Q command, 872, 876 Proposed value, 896, 897 QC (Queued Components), 1016 protected field, 231 queries. See also LINQ protected internal modifiers, 193, 194 QueriesTableAdapter class, 943 protected keyword, 189, 193, 194, 204, 230 query expressions, 116, 494, 495 protected methods, 231 query operators, 494, 495, 518 protected modifier, 193, 194 query pattern implementation, 945 ProtectionLevel property, 1034 querying element, 1051 with Entity SQL, 977—978 protocols, stateless, 1380 with LINQ to Entities, 975—977 Provider attribute, 1505 QueryOverInts( ) method, 501 provider value, 849 QueryOverStrings( ) method, 496, 497, 498 proxy class, 1018, 1046 QueryString collection, 1476 proxy code, generating QueryString property, 1418, 1419, 1420 using svcutil.exe, 1046—1047 QueryStringsWithAnonymousMethods( ) using Visual Studio 2010, 1047—1048 method, 520 PTSalesPerson class, 231, 236, 239 QueryStringsWithEnumerableAndLambda public access modifier, 168 s( ) method, 519, 520 public attribute, 655, 669 QueryStringsWithOperators( ) method, public fields, 195, 807—808 518, 520

1670

INDEX ■

Queue class, 362 reading incoming cookie data, 1499 Queue class, 377, 382—383 ReadLine( ) method, TextReader class, 82, Queue object, 382 797 Queued Components (QC), 1016 readOnly attribute, 1505 QueueUserWorkItem( ) method, 760 read-only fields, constant field data, 215— 216 readonly modifier, 216, 218 ■R ReadOnly property, DataColumn class, 891 ReadToEnd( ) method, TextReader class, radial gradient brush, 1258, 1259 797 RadialGradientBrush object, 1294 ReadXml( ) method, 889, 901 RadialGradientBrush type, 1258, 1293 ReadXmlSchema( ) method, 901 Radio class, 190, 193, 263 ReadXXXX( ) method, BinaryReader class, Radio type, 273 800 RadioButton class, 1218, 1220, 1223 real types, 1082 RadioButton control, Ink API tab, 1220— Really Simple Syndication (RSS) library, 1222 1024 RadioButton objects, 1249, 1553 Reason property, 1098 radioButtonCircle object, 1553 Receive activity, WF 4.0, 1090 RadioButtonClicked handler, 1221 Recent tab, 57, 541 RadioButtonClicked( ) method, 1223 Record Keyframe button, 1360 radioButtonRect object, 1553 record mode, 1360 Radio.cs file, 273, 277, 343 records RadiusX property, 1250 deleting, 974—975 RadiusY property, 1250 updating, 975 Random member variable, 182 Rectangle class, 213, 214, 341, 378, 1247, RangeValidator control, 1458 1256 RangeValidator type, 1459 Rectangle element, 1192 RangeValidator widget, 1460—1461 Rectangle objects, 491, 1248, 1250, 1252 Rank property, Array class, 143 Rectangle type, 157, 455, 456, 457, 458, 459, raw Predicate delegate, 491 1250, 1254, 1547, 1548 RawUrl property, 1418 Rectangle variable, 157, 213 RCW (Runtime Callable Wrapper), 714, 715 element, 1267, 1268 Read( ) member RectangleF type, 1548 BinaryReader class, 800 RectangleGeometry class, 1255 Stream class, 793 RectangleGeometry object, 1255 TextReader class, 796 rectangular array, 140, 141 ReadAllBytes( ) method, File class, 790 RectMultidimensionalArray( ) method, 141 ReadAllLines( )method, File class, 790 Redirect( ) method, 1421 ReadAllText( )method, File class, 791 redirecting users, 1422—1423 ReadBlock( ) methhod, TextReader class, ref arguments, 10, 400 797 ref keyword, 129, 483 ReadByte( ) method, FileStream class, 793 ref modifier, 126, 128—129, 159, 160 ReadByte( ) method, Stream class, 793 ref parameter, 126, 400, 429 reading, from text files, 796—797 Refactor menu, 60, 61, 336

1671

INDEX ■

refactoring code, Visual Studio 2010, 60—63 relational data, 494 reference count, 292, 293 Relations property, 887 Reference folder, 568 relationships Reference parameters, 129 class library, 8 reference, passing reference types by, 160 has-a, 5, 190, 213, 219, 232 reference types is-a, 189, 190, 219, 220, 228, 248 passing by reference, 160 parent/child, 190 passing by value, 158—160 Relative value, 1291 vs. value types, 155—156, 161—162 relaxed delegates, 414 value types containing, 157—158 Release( ) method, 292 reference variable, 290 rem opcode, 678 References folder, Solution Explorer, 57, remoting layer, 1016 620, 716 RemotingFormat member, 897 referencing RemotingFormat property, 888, 902 assemblies, 1414—1415 Remove( ) method, 98, 365, 402, 410, 1000, AutoLotDAL.dll, 1396—1409 1484, 1486, 1496, 1515 reflection Remove Parameters refactoring, 61 obtaining Type reference using remove_ prefix, 421 System.Object.GetType( ), 588—589 remove_AboutToBlow( ) method, 421 obtaining Type reference using remove_Exploded( ) method, 421 System.Type.GetType( ), 589 Remove( ) method, 1000 obtaining Type reference using typeof( RemoveAll( ) method, 402, 1484, 1486, ), 589 1496 overview, 586 RemoveAt( ) method, 1484, 1515 System.Type class, 587 RemoveFromCollection activity, WF reflection calls, longhand, 711 4.0, 1092 ReflectionOnly value, 694 RemoveInventoryRow( ) method, 934 Reflector, exploring assemblies using, 35— RemoveMemoryPressure( ) method, 36 System.GC class, 298 reflector.exe file, 36, 498, 581, 658, 755, removeon directive, 421 1151, 1157, 1290, 1327 RemoveRecord( ) method, 975 ReflectOverQueryResults( ) method, 498 removing controls, dynamically, 1435— ref/out parameters, 291 1436 RefreshGrid( ) method, 1492 Rename option, 1520 refreshing client proxy, 1056—1057 Rename refactoring, 61 RefTypeValTypeParams project, 158, 161 RenamedEventHandler delegate type, 802 Region type, 1548 rendering graphical data using GDI+ RegisterWithCarEngine( ) method, 406, Graphics type, 1548—1549 407, 408, 409 invalidating form's client area, 1551 registrating events, simplifying using obtaining Graphics object with Paint Visual Studio 2010, 423—424 event, 1549—1550 RegularExpressionValidator control, 1458 overview, 1545—1546 RegularExpressionValidator widget, 1459, System.Drawing namespace, 1547 1460 rendering graphical output, 1557 RejectChanges( ) method, 889, 893 RenderingWithShapes application, 1247

1672

INDEX ■

RenderingWithShapes project, 1263 resource-only assembly, defining, RenderingWithVisuals application, 1278 1300—1301 RenderOpen( ) method, 1279 Resources property, 1292 RenderTargetBitmap object, 1279, 1280 window-wide resources, defining, RenderTransform object, 1265, 1307 1292—1294 RenderTransform property, 1134, 1248, ResourceDictionary object, 1292 1263, 1307 elements, 1299, Reorder Parameters refactoring, 61 1321 RepeatBehavior property, 1306, 1308, 1310 RepeatBehavior.Forever method, 1309 scope, 1299 Replace( ) method, 98, 99 resource-only assembly, defining, 1300— Request object, 1476 1301 Request property, 1417, 1482 resources RequestedColor argument, 1105, 1107 managed, 311 RequestedMake argument, 1105, 1107 unmanaged, 289, 303, 305, 311 RequestedMake variable, 1110 Resources indexer, 1296 request/response cycle, 1380 Resources link, 11 RequestType property, 1418 Resources property, 1134, 1292, 1295 RequiredFieldValidator control, 1458 Resources tab, 1303 RequiredFieldValidator type, 1459 Resources view, 1322 RequiredFieldValidator widget, 1459—1460 Responding property, Reset Current menu option, System.Diagnostics.Process class, 1212 629 Reset( ) method, 344, 348 response files, for csc.exe, 47—49 ResetPoint( ) method, 390 Response property, 1417, 1421, 1482 resource system, WPF Response.Cookies property, 1498 binary resources Result property, 1095 embedding application resources, Results View option, 502 1289—1291 Resume( ) method, 742 loose resources, 1286—1287 ret opcode, 678 overview, 1285 retained-mode graphics, 1245 programmatically loading images, Rethrow activity, WF 4.0, 1092 1288—1289 rethrowing exceptions, 280 object (logical) resources return keyword, 75 {DynamicResource} markup return values, 871 extension, 1295—1296 array as, 142 {StaticResource} markup extension, interfaces as, 333 1294 ReturnType property, 594 application-level resources, 1296— Reverse( ) method, 143 1297 Reverse<>( ) method, 509 changing after extraction, 1295 Reverse( ) method, 514 extracting in Expression Blend, ReverseDigits( ) method, 461, 462 1301—1303 reversing animation, 1308—1309 merged resource dictionaries, RichTextBox control, 1228, 1231, 1234 defining, 1298—1299 RichTextBox manager, 1228

1673

INDEX ■

Right property, 1527 RSS (Really Simple Syndication) library, right-click operation, 1203 1024 Rollback( ) method, 879 rtspecialname attribute, 675 ROLLBACK statement, 878 rtspecialname token, 689 rolled back, 878 RTTI (Runtime Type Identification) Root member, DirectoryInfo class, 779 method, 252 root namespace, 30 Run element, 1227 RotateTransform object, 1263, 1264, 1307 Run( ) method, 1086, 1128 RotateTransform type, 1262 Run objects, 1231 RoundButtonStyle, 1354 Run value, 694 RoundButtonTemplate, 1350, 1351, 1353 RunAndSave value, 694 round-trip engineering, 658 runat="server" attribute, 1403, 1467, 1477 RoundTrip example, 666 RunMyApplication( ) method, 286 RountedEventArgs parameter, 1339 running processes, enumerating, 630 routed events, WPF runtime overview, 1337 activities, WF 4.0, 1091 routed bubbling events, 1338—1339 deploying .NET, 36—37 routed tunneling events, 1339—1341 exceptions, 249 RoutedEventArgs class, 1139 Runtime Callable Wrapper (RCW), 714, 715 RoutedEventHandler delegate, 1139, 1337 runtime engine routines Mono, 1577 creating custom conversion, 455—457 WF 4.0, 1083—1088 custom conversion, 460 runtime type discovery, 586 implicit conversion, 458—459 Runtime Type Identification (RTTI) routing strategies, 1337 method, 252 row filtering, 909 element, 555 RowBackground property, 1243 RuntimeBinderException class, 704, 705 element, 1191 rw object, 312 RowError property, 893 rw2 object, 312 RowFilter property, DataView class, 913 RowNotInTableException exception, 832 rows ■S deleting from DataTables, 907—908 selecting based on filter criteria, 908— S command, 872 911 safe swap function, 483 updating within DataTables, 911 SAFEARRAY data type, 6, 7 Rows category, 1243 SAFEARRAY structure, 6 Rows collection, 900, 941, 943 SalesPerson class, 226, 227, 236, 237, 239 Rows indexer, 934 SalesPerson constructor, 229 RowState enumeration, 893 SalesPerson type, 230, 231 RowState property, 893, 894—896, 919 SalesPerson.cs file, 227 RowState.Added value, 919 Samples menu selection, 1275 RowState.Deleted value, 919 sane subset, 4 RowState.Modified value, 919 satellite assemblies, 536 *.rsp file extension, 47, 48, 659 Save button, 1235

1674

INDEX ■

Save command, WPF, 1204—1206 AutoResetEvent class, 748—749 Save( ) method, 879 foreground and background save points, 879 threads, 749—750 Save value, 694 overview, 744 SaveAs( ) method, 1418 ParameterizedThreadStart delegate, SaveChanges( ) method, 958, 959, 974, 990 747 SaveFileDialog dialog box, 1183 ThreadStart delegate, 745—746 SaveFileDialog type, 1558, 1559 worker threads, 626 saving, InkCanvas data, 1226—1227 Section class, 1230 SavingChanges event, 959, 973 Section element, 1227 SavingsAccount class, 183, 184, 185 Section type, 1227 SavingsAccount object, 183, 185, 186, 187 SELECT command, 914 SayHello( ) method, 691, 697 Select items, 1213 sbyte data type, 86 Select( ) method, 519, 520, 793, 800, 908, ScaleTransform type, 1262 909, 910, 911 Scene elements list box, 1237 Select mode, 1223, 1224 node, 969 Select Mode! value, 1218 scope, 464—465 Select New Data Source option, 1451 scope ambiguity, 174, 175 Select Object editor, 1218, 1219

Web Analytics