Skip to Content
Professional Visual Basic 2012 and .NET 4.5 Programming
book

Professional Visual Basic 2012 and .NET 4.5 Programming

by Bill Sheldon, Billy Hollis, Rob Windsor, David McCarter, Gastón Hillar, Todd Herman
January 2013
Intermediate to advanced
912 pages
26h 58m
English
Wrox
Content preview from Professional Visual Basic 2012 and .NET 4.5 Programming

Basics of Reflection

As mentioned in Chapter 2, you can explore the internals of a given assembly using a process called reflection. You can find out what assemblies are loaded into your current application domain. You can discover what types reside in each assembly, and for any given type, the methods and properties exposed by the type. You can even execute a method or change a property value via reflection, even though you might not know the name of the method or property at compile time.

In this section, you'll see the basic code required for each of these operations. The code uses classes in the System.Reflection namespace, most notably the Assembly class, and each example assumes that the code module has an Imports statement to import System.Reflection.

Major classes needed to use reflection capabilities include the following:

  • Assembly—Contains members to examine an assembly's metadata and even manipulate the assembly
  • AppDomain—Contains information about the currently running application domain
  • Type—Gives access to information about a .NET type

After this section, you will also see an additional capability provided through reflection: dynamic loading. You'll see how to gain a reference to an assembly on the fly and generate an instance of a type within the assembly.

Note
While the process of reflection is powerful and enables you to perform operations that would otherwise be impossible, you should be aware of the performance implications of using reflection heavily. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Visual Basic 2012 Programmer's Reference

Visual Basic 2012 Programmer's Reference

Rod Stephens

Publisher Resources

ISBN: 9781118332139Purchase book