<PackageReference Include="System.Reflection.Emit" Version="4.6.0-preview4.19212.13" />

TypeBuilder

public sealed class TypeBuilder : Type
Defines and creates new instances of classes during run time.
public const int UnspecifiedTypeSize = 0

Represents that total size for the type is not specified.

public PackingSize PackingSize { get; }

Retrieves the packing size of this type.

public int Size { get; }

Retrieves the total size of a type.

public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor)

Returns the constructor of the specified constructed generic type that corresponds to the specified constructor of the generic type definition.

public static FieldInfo GetField(Type type, FieldInfo field)

Returns the field of the specified constructed generic type that corresponds to the specified field of the generic type definition.

public static MethodInfo GetMethod(Type type, MethodInfo method)

Returns the method of the specified constructed generic type that corresponds to the specified method of the generic type definition.

public void AddInterfaceImplementation(Type interfaceType)

Adds an interface that this type implements.

Gets a TypeInfo object that represents this type.

public ConstructorBuilder DefineConstructor(MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes)

Adds a new constructor to the type, with the given attributes and signature.

public ConstructorBuilder DefineConstructor(MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)

Adds a new constructor to the type, with the given attributes, signature, and custom modifiers.

Defines the default constructor. The constructor defined here will simply call the default constructor of the parent.

public EventBuilder DefineEvent(string name, EventAttributes attributes, Type eventtype)

Adds a new event to the type, with the given name, attributes and event type.

public FieldBuilder DefineField(string fieldName, Type type, FieldAttributes attributes)

Adds a new field to the type, with the given name, attributes, and field type.

public FieldBuilder DefineField(string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)

Adds a new field to the type, with the given name, attributes, field type, and custom modifiers.

Defines the generic type parameters for the current type, specifying their number and their names, and returns an array of GenericTypeParameterBuilder objects that can be used to set their constraints.

public FieldBuilder DefineInitializedData(string name, byte[] data, FieldAttributes attributes)

Defines initialized data field in the .sdata section of the portable executable (PE) file.

public MethodBuilder DefineMethod(string name, MethodAttributes attributes)

Adds a new method to the type, with the specified name and method attributes.

public MethodBuilder DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention)

Adds a new method to the type, with the specified name, method attributes, and calling convention.

public MethodBuilder DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)

Adds a new method to the type, with the specified name, method attributes, calling convention, and method signature.

public MethodBuilder DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)

Adds a new method to the type, with the specified name, method attributes, calling convention, method signature, and custom modifiers.

public MethodBuilder DefineMethod(string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)

Adds a new method to the type, with the specified name, method attributes, and method signature.

public void DefineMethodOverride(MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration)

Specifies a given method body that implements a given method declaration, potentially with a different name.

public TypeBuilder DefineNestedType(string name)

Defines a nested type, given its name.

public TypeBuilder DefineNestedType(string name, TypeAttributes attr)

Defines a nested type, given its name and attributes.

public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent)

Defines a nested type, given its name, attributes, and the type that it extends.

public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, int typeSize)

Defines a nested type, given its name, attributes, the total size of the type, and the type that it extends.

public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize)

Defines a nested type, given its name, attributes, the type that it extends, and the packing size.

public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)

Defines a nested type, given its name, attributes, size, and the type that it extends.

public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, Type[] interfaces)

Defines a nested type, given its name, attributes, the type that it extends, and the interfaces that it implements.

public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)

Adds a new property to the type, with the given name, attributes, calling convention, and property signature.

public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)

Adds a new property to the type, with the given name, calling convention, property signature, and custom modifiers.

public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes)

Adds a new property to the type, with the given name and property signature.

public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)

Adds a new property to the type, with the given name, property signature, and custom modifiers.

Defines the initializer for this type.

public FieldBuilder DefineUninitializedData(string name, int size, FieldAttributes attributes)

Defines an uninitialized data field in the .sdata section of the portable executable (PE) file.

public bool IsCreated()

Returns a value that indicates whether the current dynamic type has been created.

public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)

Sets a custom attribute using a specified custom attribute blob.

public void SetCustomAttribute(CustomAttributeBuilder customBuilder)

Set a custom attribute using a custom attribute builder.

public void SetParent(Type parent)

Sets the base type of the type currently under construction.