Building and Consuming a Multifile Assembly

Now that you have constructed and consumed a single-file assembly, let's examine the process of building a multifile assembly. Recall that a multifile assembly is simply a collection of related modules which has nothing to do with the Visual Basic 2008 Module keyword that are deployed and versioned as a single logical unit. At the time of this writing, Visual Studio 2008 does not support a VB 2008 multifile assembly project template. Therefore, you will need to make use of the command-line...

Defining the Initial Class Type

Open the AutoLotDAL project in Visual Studio 2008, insert a new class type named InventoryDALDisLayer using the Project gt - Add New Item menu option, and ensure you have a public class type in your new code file, wrapped in a new namespace named AutoLotDisconnectedLayer. Unlike the connection-centric InventoryDAL type, this new class will not need to provide custom open close methods, as the data adapter will handle the details automatically. To begin, add a custom constructor that sets a...

This method can receive anything implementing IDraw3D

Sub DrawIn3D ByVal itf3d As IDraw3D Console.WriteLine - gt Drawing IDraw3D compatible type itf3d.Draw3D End Sub If we were to now call this method while cycling through the array of Shapes, only the IDraw3D-compatible types are sent into our new subroutine see Figure 9-5 for output . Dim itfPointy As IPointy For Each s As Shape In myShapes If TypeOf s Is IPointy Then itfPointy CType s, IPointy Console.WriteLine 0 has 1 points., s.PetName, itfPointy.Points Else Console.WriteLine 0 does not...

VB 2008 Attribute Shorthand Notation

If you were reading closely, you may have noticed that the actual class name of the lt Obsolete gt attribute is ObsoleteAttribute, not Obsolete. As a naming convention, all .NET attributes including custom attributes you may create yourself are suffixed with the Attribute token. However, to simplify the process of applying attributes, the VB 2008 language does not require you to type in the Attribute suffix. Given this, the following iteration of the HorseAndBuggy type is identical to the...

Understanding WCF Bindings

Once a contract or a set of contracts has been defined and implemented within your service library, the next logical step is to build a hosting agent for the WCF service itself. As mentioned, you have a variety of possible hosts to choose from, all of which must specify the bindings used by remote callers to gain access to the service type's functionality. Choosing a set of bindings is one area that makes WCF development quite different from .NET remoting and or XML web service development in...

Add any initialization after the InitializeComponent call

colorDlg New ColorDialog Text Click on me to change the color End Sub Private Sub MainForm_MouseDown ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.MouseEventArgs _ Handles MyBase.MouseDown If colorDlg.ShowDialog lt gt Windows.Forms.DialogResult.Cancel Then currColor colorDlg.Color Me.BackColor currColor ' Show current color. Dim strARGB As String colorDlg.Color.ToString MessageBox.Show strARGB, Color is End If End Sub End Class

The RepeatButton Type

The final ButtonBase-derived type to discuss is the RepeatButton type, also defined within System.Windows.Controls.Primitives. This type also has a default look and feel to a standard Button however, it supports the ability to continuously fire its Click event when the end user has the widget in a pressed state. The frequency in which it will fire the Cl ick event is dependent upon the values you assign to the Delay and Interval properties both of which are recorded in milliseconds . In...

Basic Input and Output with the Console Class

In addition to the members in Table 3-2, the Console type defines a set of methods to capture input and output, all of which are shared and are therefore called by prefixing the name of the class Console to the method name. As you have seen, WriteLine pumps a text string including a carriage return to the output stream. The Write method pumps text to the output stream without a carriage return. ReadLine allows you to receive information from the input stream up until the carriage return, while...

The SystemConsole Class

Almost all of the example applications created over the course of the initial chapters of this text make extensive use of the System.Console class. While it is true that a console user interface sometimes called a CUI is not as enticing as a graphical user interface GUI or web-based front end, restricting the early examples to console programs will allow us to keep focused on the syntax of Visual Basic and the core aspects of the .NET platform, rather than dealing with the complexities of...

Adding a Code Activity

The first activity you will add in the sequence is a Code activity. To do so, activate the designer, drag a Code activity component from the Windows Workflow Toolbox, and drop it onto the line connecting the starting and ending points of the workflow. Next, use the Properties window to rename this activity as ShowInstructionsActivity using the Name property. At this point, your designer should look like Figure 26-6. Figure 26-6. A not quite ready for prime time Code activity Figure 26-6. A not...

Designing the StatusStrip

Next, place a StatusStrip control onto the designer and rename this control to mainStatusStrip note this control automatically docks to the bottom of the designer window . Initially, a StatusStrip contains no panes whatsoever. To add panes, you may take various approaches Author the code by hand without designer support perhaps using a helper method named CreateStatusStrip that is called in the form's constructor . Add the items via a dialog box activated through the Edit Items link using the...

Note As an alternative you can configure a GridView using the inline editor

If you examine the opening declaration of the GridView control, you will see that the DataSourceID property has been set to the SqlDataSource you just defined lt asp GridView ID GridView1 runat server AutoGenerateColumns False DataKeyNames CarID The SqlDataSource type is where a majority of the action is taking place. In the markup that follows, notice that this type has recorded the necessary SQL statements with parameterized queries no less to interact with the Inventory table of the Cars...

Table 2711 Members of the ToolStripMenuItem Type MemberMeaning in Life

Checked Gets or sets a value indicating whether a check mark appears beside the text of the CheckOnClick Gets or sets a value indicating whether the ToolStripMenuItem should automatically appear checked unchecked when clicked Enabled Gets or sets a value indicating whether the ToolStripMenuItem is enabled Let's extend the previous pop-up menu to display a check mark next to the currently selected menu item. Setting a check mark on a given menu item is not at all difficult just set the Checked...

The Integrated Help System

The final aspect of Visual Studio 2008 you must be comfortable with from the outset is the fully integrated help system. The .NET Framework 3.5 SDK documentation aka the MSDN Library is extremely good, very readable, and full of useful information. Given the huge number of predefined .NET types which number well into the thousands , you must be willing to roll up your sleeves and dig into the provided documentation. If you resist, you are doomed to a long, frustrating, and painful existence as...

IDL Attributes

To begin parsing out this IDL, notice that IDL syntax contains blocks of code placed in square brackets . Within these brackets is a comma-delimited set of IDL keywords, which are used to disambiguate the very next thing the item to the right of the block or the item directly below the block . These blocks are IDL attributes that serve the same purpose as .NET attributes i.e., they describe something . One key IDL attribute is uuid , which is used to assign the globally unique identifier GUID...

Building a Polymorphic Interface with MustOverride

When a class has been defined as an abstract base class via the MustInherit keyword , it may define any number of abstract members. Abstract members can be used whenever you wish to define a member that does not supply a default implementation. By doing so, you enforce a polymorphic interface on each descendant, leaving them to contend with the task of providing the details behind your abstract methods or properties. Simply put, an abstract base class's polymorphic interface simply refers to...

Table 71 Core Members of the SystemException Type SystemException Property

Data This property retrieves a collection of key value pairs represented by an object implementing IDictionary that provides additional, user-defined information about the exception. By default, this collection is empty. HelpLink This property returns a URI to a help file describing the error in full InnerException This read-only property can be used to obtain information about the previous exception s that caused the current exception to occur. The previous exception s are recorded by passing...

Exploring the Manifest of SharedCarLibClient

Recall that when you generate a strong name for an assembly, the entire public key is recorded in the assembly manifest. On a related note, when a client references a strongly named assembly, its manifest records a condensed hash-value of the full public key, denoted by the .publickeytoken tag. If you were to open the manifest of SharedCarLibClient.exe using ildasm.exe, you would find something like the following .publickeytoken 21 9E F3 80 C9 34 8A 38 .ver 1 0 0 0 If you compare the value of...

Exploring the CIL

Recall that an assembly does not contain platform-specific instructions rather, it contains platform-agnostic CIL. When the .NET runtime loads an assembly into memory, the underlying CIL is compiled using the JIT compiler into instructions that can be understood by the target platform. If you double-click the TurboBoost method of the SportsCar class, ildasm.exe will open a new window showing the CIL instructions, looking something like the following .method public hidebysig virtual instance...

Info Fju

Configured Assemblies i p Remoting Services gt Qjp Runtime Security Policy j Applications .NET Framework 2.0 Configuration allows you to configure assemblies, remoting services, and code access security policy specific to version 2.0 of the .NET Framework. Note This version of the .NET Framework Configuration tool will not adjust settings for previous or later versions of the .NET Framework. Use the corresponding configuration tool to adjust settings for those versions.

The VB TryCast Keyword

On a final note, VB also offers one final manner to perform runtime type conversions using TryCast . Again, syntactically, TryCast looks identical to CType .The difference is that TryCast returns Nothing if the arguments are not related by inheritance or interface implementation, rather than throwing a runtime exception. Thus, rather than wrapping a call to CType or DirectCast within Try Catch logic, you can simply test the returned reference within a conditional statement. This being said,...

System.data.sqlserverce Version 3.5.0.0 Culture Neutral Publickeytoken

lt add name Odbc Data Provider invariant System.Data.Odbc description .Net Framework Data Provider for Odbc System.Data, Version 2.0.0.0, Culture neutral, PublicKeyToken b77a5c561934e089 gt lt add name OleDb Data Provider invariant System.Data.OleDb description .Net Framework Data Provider for OleDb System.Data, Version 2.0.0.0, Culture neutral, PublicKeyToken b77a5c561934e089 gt lt add name OracleClient Data Provider description .Net Framework Data Provider for Oracle...

The RCW Hiding LowLevel COM Interfaces

The final core service provided by the RCW is to consume a number of low-level COM interfaces. Because the RCW tries to do everything it can to fool the .NET client into thinking it is communicating with a native .NET type, the RCW must hide various low-level COM interfaces from view. For example, when you build a COM class that supports IConnectionPointContainer and maintains a subobject or two supporting IConnectionPoint , the coclass in question is able to fire events back to the COM client....

Expose object through a custom property

Public Property Benefits As BenefitPackage Get empBenefits value End Set End Property In the following updated Main method, notice how we can interact with the internal BenefitsPackage object within the Employee object Dim chucky As New Manager Chucky, 45, 101, 30000, 222-22-2222, 90 Dim cost As Double chucky.GetBenefitCost Console.ReadLine End Sub End Module

Using the WebCentric WCF Service Project Template

Using the File gt - New gt - Web Site menu option, create a new WCF Service named VbAutoLot-WCFService, exposed from the following URI http localhost VbAutoLotWCFService see Figure 25-19 . Be sure the Location drop-down list has HTTP as the active selection. Once you have done so, set a reference to the AutoLotDAL.dll assembly you created in Chapter 22 via the Website gt - Add Reference menu option . Much like a WCF Service Library project, you have been given some example starter code located...

Working with HatchBrushes

The System.Drawing.Drawing2D namespace defines a Brush-derived type named HatchBrush. This type allows you to fill a region using a very large number of predefined patterns, represented by the HatchStyle enumeration. Here is a partial list of names Enum HatchStyle Horizontal Vertical ForwardDiagonal BackwardDiagonal Cross When constructing a HatchBrush, you need to specify the foreground and background colors to use during the fill operation. To illustrate, let's rework the logic seen...

Reflecting on Method Parameters and Return Values

So far, so good Let's make one minor enhancement to the current application. Specifically, you will update the ListMethods helper function to list not only the name of a given method, but also the return value and incoming parameters. The MethodInfo type provides the ReturnType property and GetParameters method for these very tasks. In the following code, notice that you are building a string type that contains the type and name of each parameter using a nested For Each loop Public Sub...

File Header Values

14C machine x86 4 number of sections 440B2782 time date stamp Sun Mar 05 12 01 38 2006 0 file pointer to symbol table 0 number of symbols EO size of optional header 210E characteristics Executable Line numbers stripped Symbols stripped 32 bit word machine DLL 10B magic PE32 8.00 linker version 2000 size of code 3000 size of initialized data 0 size of uninitialized data 3DEE entry point 00403DEE Figure 15-1. An assembly's Win32 file header information ic gt dumpbin clrheader CarLibrary.dll...

Note Despite the name the SqlDataSource provider can be configured to

With a few simple mouse clicks, you can configure the GridView to automatically select, update, and delete records of the underlying data store. While this zero-code mindset greatly simplifies the amount of boilerplate code, understand that this simplicity comes with a loss of control and may not be the best approach for an enterprise-level application. This model can be wonderful for low-trafficked pages, prototyping a website, or smaller in-house applications. To illustrate how to work with...

Building a Reusable WF Code Library

These first examples allowed you to play around with various WF activities at design time, interact with the workflow runtime engine by passing custom parameters , and get into the overall WF mind-set using a console-based WF host. While this is great from a learning point of view, I bet you can easily envision building workflow-enabled Windows Forms applications, WPF applications, or ASP.NET web applications. Furthermore, I am sure you can imagine the need to reuse a workflow across numerous...

XBAP Applications

WPF also allows you to build applications that can be hosted within a web browser. This flavor of WPF application is termed a XAML browser application, or XBAP Under this model, the end user navigates to a given URL, at which point the XBAP application which takes an .xbap file extension is transparently downloaded and installed to the local machine. Unlike a traditional ClickOnce installation for an executable application, however, the XBAP program is hosted directly within the browser and...

The Role of the Application Class

The Application class defines numerous shared members that allow you to control various low-level behaviors of a Windows Forms application. For example, the Application class defines a set of members that allow you to respond to events such as application shutdown and idle-time processing. In addition to the Run method, here are some other methods to be aware of DoEvents Provides the ability for an application to process messages currently in the message queue during a lengthy operation. This...

The Two Faces of ADONET

The ADO.NET libraries can be used in two conceptually unique manners connected or disconnected. When you are making use of the connected layer, your code base will explicitly connect to and disconnect from the underlying data store. When you are using ADO.NET in this manner, you typically interact with the data store using connection objects, command objects, and data reader objects. The disconnected layer, which is the subject of Chapter 23, allows you to manipulate a set of DataTable objects...

Public Fields Private Fields and Public Properties

Notice that in each of these classes, I have defined the field data using the Public keyword, just to simplify the example. Of course, private data exposed using public properties would be preferable from an OO point of view. Also, for the sake of simplicity, I have not defined any custom constructors on these types, and therefore all unassigned field data will receive the expected default values. OO design principles aside, you may wonder how the various formatters expect a type's field data...

Info Iko

Figure 15-14. The .NETFramework Configuration utility Figure 15-14. The .NETFramework Configuration utility To build a client .config file using this utility, your first step is to add the application to configure by right-clicking the Applications node and selecting Add. In the resulting dialog box, you may find the application you wish to configure, provided that you have executed it using Windows Explorer. If this is not the case, click the Other button and navigate to the location of the...

The Role of MSMQ

The Microsoft Message Queuing MSMQ API allows developers to build distributed systems that need to ensure reliable delivery of message data on the network. As we all know too well, in any distributed system there is the risk that a network server is down, a database is offline, or connections are lost for mysterious reasons. Furthermore, a number of applications need to be constructed in such a way that they hold message data for delivery at a later time known as queuing data . At first, MSMQ...

The Role of the Me Keyword

Like earlier additions of Visual Basic, VB 2008 supplies a Me keyword that provides access to the current class instance. One possible use of the Me keyword is to resolve name clashes, which can arise when an incoming parameter is named identically to a data field of the type. Of course, ideally you would simply adopt a naming convention that does not result in such ambiguity however, to illustrate this use of the Me keyword, update your Motorcycle class with a new public String field named...

Working with Parameterized Command Objects

Currently, the insert, update, and delete logic for the InventoryDAL type uses hard-coded string literals for each SQL query. As you may know, a parameterized query can be used to treat SQL parameters as objects, rather than a simple blob of text. Treating SQL queries in a more object-oriented manner not only helps reduce the number of typos given strongly typed properties , but parameterized queries typically execute much faster than a literal SQL string, in that they are parsed exactly once...

Understanding the DataRowVersion Property

Beyond maintaining the current state of a row via the RowState property, a DataRow object maintains three possible versions of the data it contains via the DataRowVersion property. When a DataRow object is first constructed, it contains only a single copy of data, represented as the current version. However, as you programmatically manipulate a DataRow object via various method calls , additional versions of the data spring to life. Specifically, the DataRowVersion property can be set to any...

Tell the Form to repaint itself

Notice that using the sender argument, you are able to determine the name of the ToolStripMenuItem member variable in order to set the current text size. Once you have done so, the call to Invalidate fires the Paint event, which will cause your Paint event handler to execute. The final step is to inform the form which ContextMenuStrip it should display when the right mouse button is clicked in its client area. To do so, simply use the Properties window to set the ContextMenuStrip property equal...

ADONET Part I The Connected Layer

As you would expect, the .NET platform defines a number of namespaces that allow you to interact with machine local and remote relational databases. Collectively speaking, these namespaces are known as ADO.NET. In this chapter, once I frame the overall role of ADO.NET, I'll move on to discuss the topic of ADO.NET data providers. As you will see, the .NET platform supports numerous data providers, each of which is optimized to communicate with a specific database management system Microsoft SQL...

Helper enum for images

Public Enum AnimFrames Lemon1 Lemon2 Lemon3 AboutToBlow EngineBlown End Enum The CarControl type maintains a good number of private data points to represent the animation logic. Here is the rundown of each member Public Class CarControl ' State data. Private currFrame As AnimFrames AnimFrames.Lemon1 Private currMaxFrame As AnimFrames AnimFrames.Lemon3 Private IsAnim As Boolean Private currSp As Integer 50 Private maxSp As Integer 100 Private carPetName As String Lemon Private bottomRect As New...

Building Finalizable and Disposable Types

At this point, we have seen two different approaches to construct a class that cleans up internal unmanaged resources. On the one hand, we could override System.Object.Finalize . Using this technique, we have the peace of mind that comes with knowing the object cleans itself up when garbage collected whenever that may be without the need for user interaction. On the other hand, we could implement IDisposable to provide a way for the object user to clean up the object as soon as it is finished....

Transforming XML Code Comments via NDoc

Now that you have generated an .xml file that contains your source code comments, you may be wondering exactly what to do with it. Sadly, Visual Studio 2008 does not provide a built-in utility that transforms XML data into a more user-friendly help format such as an HTML page . If you are comfortable with the ins and outs of XML transformations, you are, of course, free to manually create your own style sheets. A simpler alternative, however, are the numerous third-party tools that will...

Note The code comments that are placed within the SessionEnd event handler will

Like the HttpApplicationState type, the HttpSessionState may hold any System.Object-derived type, including your custom classes. For example, assume you have a new web application SessionState that defines a new class named UserShoppingCart within a file named UserShoppingCart.vb Public Class UserShoppingCart Public desiredCar As String Public desiredCarColor As String Public downPayment As Single Public isLeasing As Boolean Public dateOfPickUp As DateTime Public Overrides Function ToString As...

Handling WindowLevel Mouse Events

Much like Windows Forms, the WPF API provides a number of events you can capture in order to interact with the mouse. Specifically, the UIElement base class defines a number of mouse-centric events such as MouseMove, MouseUp, MouseDown, MouseEnter, MouseLeave, and so forth. Consider, for example, the act of handling the MouseMove event. This event works in conjunction with the System.Windows.Input.MouseEventHandler delegate, which expects its target to take a System.Windows.Input.MouseEventArgs...

The Point and PointF Types

The first utility types you should be aware of are Point and PointF, which define a number of helpful members, including , -, , lt gt The Point type overloads various VB operators. X, Y These members provide access to the underlying x, y values of the Point. IsEmpty This member returns true if x and y are both set to 0. To illustrate working with the GDI utility types, here is a Console Application named DrawingUtilTypes that makes use of the System.Drawing.Point type be sure to set a reference...

Assemblies Are Versionable Units

.NET assemblies are assigned a four-part numerical version number of the form major.minor. build.revision if you do not provide a version number explicitly, your assembly is automatically assigned a version of 0.0.0.0 . This number, in conjunction with an optional public key value, allows multiple versions of the same assembly to coexist in harmony on a single machine. Formally speaking, assemblies that provide public key information are termed strongly named. As you will see in this chapter,...

Anonymous Types Containing Anonymous Types

You don't control the name of the anonymous type. Anonymous types always extend System.Object. Anonymous types cannot support events, custom methods, custom operators, or custom overrides. Anonymous types are always implicitly sealed. Anonymous types are always created using the default constructor. However, when programming with the LINQ technology set, you will find that in many cases this syntax can be very helpful when you wish to quickly model the overall shape of an entity rather than...

Establishing the ABCs Within an Appconfig File

When you are building a host for a WCF service type, you will follow a very predictable set of steps some via configuration and some via code 1. Define the endpointfor the WCF service being hosted within the host's configuration file. 2. Programmatically make use of the ServiceHost type to expose the service types available from this endpoint. 3. Ensure the host remains running to service incoming client request. Obviously, this step is not required if you are hosting your service types using a...