O'Reilly logo

Visual Basic 2010 Unleashed by Alessandro Del Sole

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating Code at Runtime with Reflection.Emit

The System.Reflection.Emit namespace provides objects for generating assemblies, types, and type members at runtime. Basically you need to perform the following operations sequentially:

1. Create an in-memory assembly within the current application domain with an instance of the AssemblyBuilder class.

2. Create a module for containing types via an instance of the ModuleBuilder class.

3. Create types with instances of the TypeBuilder class.

4. Add members to the TypeBuilder via XBuilder objects, such as MethodBuilder, FieldBuilder, and PropertyBuilder.

5. Save the assembly to disk if required.

The code in Listing 47.4 demonstrates how to create dynamically a simple implementation of the Person ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required