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 int UnspecifiedTypeSize; 
// =0
                  // Public Instance Properties
   public override Assembly Assembly{get; }           
// overrides Type
   public override string AssemblyQualifiedName{get; }
// overrides Type
   public override Type BaseType{get; }  
// overrides Type
   public override Type DeclaringType{get; }          
// overrides Type public ...

Get C# in a Nutshell, Second Edition 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.