For the attributes in the metadata to be useful, you need a way to access them, ideally during runtime. The classes in the Reflection namespace, along with the System.Type and System.TypedReference classes, provide support for examining and interacting with the metadata.
Reflection is generally used for any of four tasks:
This might be used by tools and utilities that wish to display metadata.
This allows the programmer to invoke properties and methods on objects dynamically instantiated based on type discovery. This is also known as dynamic invocation .
The ultimate use of reflection is to create new types at runtime and then to use those types to perform tasks. You might do this when a custom class, created at runtime, will run significantly faster than more generic code created at compile time. An example is offered later in this chapter.
In this section, you will use the Visual Basic .NET Reflection support to read the metadata in the MyMath class.
Start by initializing an object of the type MemberInfo. This object, ...