Building Client/Server Applications with VB .NET: An Example-Driven Approach is based on Release 1.0 of the .NET Framework / Release 1.0 of Visual Studio .NET + .NET Framework Service Pack 1. Jeff Levinson walks readers through how to write a complete application- no “snippets” of code- and will show readers examples of how, when, and why to perform a task.
Building Client/Server Applications with VB .NET: An Example-Driven Approach will be the manual on software development for Enterprise application development.
One other ability of reflection that I wanted to mention (but that I will not cover in this book) is the ability to dynamically create code. The namespace that contains the classes necessary to do this is the Reflection.Emit namespace. Dynamic generation of code can get very complicated, so you should be careful about using this ability, but you can do some incredible things with it. Imagine if you have an application that performs complex calculations, but you do not necessarily know what all of those calculations are beforehand. Say you have given the users the ability to create calculations later and specify how the application processes the calculation. To do this you might take a calculation and dynamically generate the code needed to process the calculation, and then you gain the ability for an application to be expanded without any additional coding by a developer! I do not expect this ability to catch on overnight because it is a highly complex area of development. To develop code using Reflection.Emit, you need to know a great deal about the Microsoft Intermediate Language (MSIL). An excellent book on the subject is Compiling for the .NET Common Language Runtime by John Gough (Prentice Hall, 2001).
The root of all reflection is the System.Attribute class. An attribute class provides information about a coding construct. So what is an attribute class? An attribute class is a class you can create and, for lack of a better description, “attach” to anything. You could attach them to a class, property, method, structure, enum, and so on. You can designate properties that only allow an attribute class to be attached to certain types of code structures or to everything-it is completely up to you. And how does this help you? It allows you to describe, or give additional properties to, a specific piece of code. Using reflection, you can examine these classes to learn information about your code elements.
NOTE Attribute classes are passive. That is, they are compiled into the code, and they cannot react to changes in data-they can only examine the data after the fact. So, if you need to stop a property from being changed unless it follows certain rules (as opposed to changing the value and marking it as a broken rule), you need to use a combination of attribute classes and business rule checking as shown in earlier chapters.
Used properly, reflection can make classes more flexible and more reusable. It can also give you the ability to dynamically generate information based on your classes. The example you will see first demonstrates that ability. After you have worked through this example, you will probably find some creative ways to use this unique and awesome ability of the .NET Framework.