Invoking Code Dynamically
Reflection also enables you to execute 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 44.3.
Imports System.ReflectionModule DynamicCode Sub DynCode() Dim asm = Assembly.LoadFrom("People.dll") 'Gets the type definition Dim personType = asm.GetType("People.Person") 'Gets the LastName property definition Dim lastNameProperty As PropertyInfo ...
Get Visual Basic 2015 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.