Invoking Code Dynamically

Reflection also enables executing dynamic code, meaning that you can pick up types defined within an assembly, creating instances and invoking types from Visual Basic code without having a reference to that assembly. For example, imagine you want to load the People.dll assembly and create and populate an instance of the Person class, as shown in Listing 47.3.

Listing 47.3 Creating and Running Dynamic Code

image

image

When you have the type instance, you invoke the GetProperty method to get a reference of the desired property. This ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.