O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

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

Name

TypeBuilder

Synopsis

This class represents a dynamically created type in a dynamic module (ModuleBuilder object). Generally, a type is either a class or an interface. To create a TypeBuilder, use the overloaded ModuleBuilder.DefineType() method. Depending on which overload you use, you can specify different information including the type name, superclass, and implemented interfaces. You can also use the System.Reflection.TypeAttributes enumeration to specify other options, such as making a class sealed, abstract, or public, or defining it as an interface. Once the type is created, you can add members such as constructors, events, fields, properties, methods, and other nested types, using the corresponding Define method.

Before using a type you created, you must use the CreateType() method to get a Type object. After that, you can instantiate the Type with the System.Activator.CreateInstance() method, and invoke members of the type with the System.Type.InvokeMember() method. After creating a type, you can no longer use TypeBuilder methods that would change the type, such as a Define method.

public sealed class TypeBuilder : Type {
// Public Static Fields
   public const field int UnspecifiedTypeSize;                   // =0
                  // Public Instance Properties
   public override field Assembly Assembly{get; }                // overrides Type
   public override field string AssemblyQualifiedName{get; }     // overrides Type
   public override field Type BaseType{get; }                    // overrides Type
   public override field Type DeclaringType{get; ...

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