Show / Hide Table of Contents

Class TypeBuilderExtensions

Provides useful extensions for generating members using the TypeBuilder class.

Inheritance
object
TypeBuilderExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.TypeFactory.dll
Syntax
public static class TypeBuilderExtensions

Methods

| Edit this page View Source

AddAutoProperty(TypeBuilder, string, Type)

Adds a public auto‑implemented property to the type.

Declaration
public static PropertyBuildInfo AddAutoProperty(this TypeBuilder tb, string name, Type type)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which to create the new auto‑implemented property.

string name

Name of the new property.

Type type

Type of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the constructed property.

| Edit this page View Source

AddAutoProperty(TypeBuilder, string, Type, MemberAccess)

Adds an auto‑implemented property to the type.

Declaration
public static PropertyBuildInfo AddAutoProperty(this TypeBuilder tb, string name, Type type, MemberAccess access)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which to create the new auto‑implemented property.

string name

Name of the new property.

Type type

Type of the new property.

MemberAccess access

Access level of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the constructed property.

| Edit this page View Source

AddAutoProperty(TypeBuilder, string, Type, MemberAccess, bool)

Adds an auto‑implemented property to the type.

Declaration
public static PropertyBuildInfo AddAutoProperty(this TypeBuilder tb, string name, Type type, MemberAccess access, bool @virtual)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which to create the new auto‑implemented property.

string name

Name of the new property.

Type type

Type of the new property.

MemberAccess access

Access level of the new property.

bool virtual

If true, the property will be defined as virtual and can be overridden in a derived class.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the constructed property.

| Edit this page View Source

AddAutoProperty<T>(TypeBuilder, string)

Adds a public auto‑implemented property to the type.

Declaration
public static PropertyBuildInfo AddAutoProperty<T>(this TypeBuilder tb, string name)
Parameters
Type Name Description
TypeBuilder tb

Type constructor in which to create the new auto‑implemented property.

string name

Name of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the constructed property.

Type Parameters
Name Description
T

Type of the new property.

| Edit this page View Source

AddComputedProperty(TypeBuilder, string, Type, Action<ILGenerator>)

Adds a computed property to the type.

Declaration
public static PropertyBuildInfo AddComputedProperty(this TypeBuilder tb, string name, Type type, Action<ILGenerator> getterDefinition)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Type type

Type of the new property.

Action<ILGenerator> getterDefinition

Action that implements the instructions to be executed inside the get accessor of the computed property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

| Edit this page View Source

AddComputedProperty<T>(TypeBuilder, string, Action<ILGenerator>)

Adds a computed property to the type.

Declaration
public static PropertyBuildInfo AddComputedProperty<T>(this TypeBuilder tb, string name, Action<ILGenerator> getterDefinition)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Action<ILGenerator> getterDefinition

Action that implements the instructions to be executed inside the get accessor of the computed property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

Type Parameters
Name Description
T

Type of the new property.

| Edit this page View Source

AddConstantProperty(TypeBuilder, string, Type, object?)

Adds a property with a constant value.

Declaration
public static PropertyBuildInfo AddConstantProperty(this TypeBuilder tb, string name, Type type, object? value)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Type type

Type of the new property.

object value

Constant value to assign.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

| Edit this page View Source

AddConstantProperty<T>(TypeBuilder, string, T)

Adds a property with a constant value.

Declaration
public static PropertyBuildInfo AddConstantProperty<T>(this TypeBuilder tb, string name, T value)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

T value

Constant value to assign.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

Type Parameters
Name Description
T

Type of the new property.

| Edit this page View Source

AddEvent(TypeBuilder, string)

Adds an event to the type.

Declaration
public static EventBuildInfo AddEvent(this TypeBuilder builder, string name)
Parameters
Type Name Description
TypeBuilder builder

TypeBuilder in which the new event and its required helper methods will be created.

string name

Name of the new event.

Returns
Type Description
EventBuildInfo

An EventBuildInfo that contains information about the event that has been defined.

| Edit this page View Source

AddEvent<TEventArgs>(TypeBuilder, string)

Adds an event to the type.

Declaration
public static EventBuildInfo AddEvent<TEventArgs>(this TypeBuilder builder, string name) where TEventArgs : EventArgs
Parameters
Type Name Description
TypeBuilder builder

TypeBuilder in which the new event and its required helper methods will be created.

string name

Name of the new event.

Returns
Type Description
EventBuildInfo

An EventBuildInfo that contains information about the event that has been defined.

Type Parameters
Name Description
TEventArgs

Type of event arguments to pass when the event occurs.

| Edit this page View Source

AddEvent<TEventHandler, TEventArgs>(TypeBuilder, string)

Adds an event to the type.

Declaration
public static EventBuildInfo AddEvent<TEventHandler, TEventArgs>(this TypeBuilder builder, string name) where TEventHandler : Delegate where TEventArgs : EventArgs
Parameters
Type Name Description
TypeBuilder builder

TypeBuilder in which the new event and its required helper methods will be created.

string name

Name of the new event.

Returns
Type Description
EventBuildInfo

An EventBuildInfo that contains information about the event that has been defined.

Type Parameters
Name Description
TEventHandler

Event handler delegate. Must follow the standard event handler signature, i.e. a void-returning method that takes an object sender and a TEventArgs argument.

TEventArgs

Type of event arguments to pass when the event occurs.

| Edit this page View Source

AddEvent<TEventHandler, TSender, TEventArgs>(TypeBuilder, string)

Adds an event to the type.

Declaration
public static EventBuildInfo AddEvent<TEventHandler, TSender, TEventArgs>(this TypeBuilder builder, string name) where TEventHandler : Delegate where TEventArgs : EventArgs
Parameters
Type Name Description
TypeBuilder builder

TypeBuilder in which the new event and its required helper methods will be created.

string name

Name of the new event.

Returns
Type Description
EventBuildInfo

An EventBuildInfo that contains information about the event that has been defined.

Type Parameters
Name Description
TEventHandler

Event handler delegate. Must follow the standard event handler signature, i.e. a void-returning method that takes a TSender (typically object) and a TEventArgs argument.

TSender

Type of the object that raises the event. Defaults to object.

TEventArgs

Type of event arguments to pass when the event occurs.

| Edit this page View Source

AddOverride(TypeBuilder, MethodInfo)

Adds an override for the specified method.

Declaration
public static MethodBuildInfo AddOverride(this TypeBuilder tb, MethodInfo method)
Parameters
Type Name Description
TypeBuilder tb

Type constructor in which to create the override.

MethodInfo method

Method to override. Must exist in the base type.

Returns
Type Description
MethodBuildInfo

A MethodBuildInfo representing the new method.

| Edit this page View Source

AddProperty(TypeBuilder, string, Type, bool, MemberAccess, bool)

Adds a property to the type without get or set implementations.

Declaration
public static PropertyBuildInfo AddProperty(this TypeBuilder tb, string name, Type type, bool writable, MemberAccess access, bool @virtual)
Parameters
Type Name Description
TypeBuilder tb

Type constructor in which to create the property.

string name

Name of the new property.

Type type

Type of the new property.

bool writable

true to create a property that includes a write accessor (set); false to omit the write accessor.

MemberAccess access

Access level of the new property.

bool virtual

If true, the property will be virtual and can be overridden in derived classes.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the constructed property.

Remarks

The generated property requires that the accessors be implemented before the type is built.

| Edit this page View Source

AddProperty<T>(TypeBuilder, string)

Adds a property to the type without implementations of get or set.

Declaration
public static PropertyBuildInfo AddProperty<T>(this TypeBuilder tb, string name)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

Type Parameters
Name Description
T

Type of the new property.

Remarks

The generated property requires that the accessors be implemented before the type is built.

| Edit this page View Source

AddProperty<T>(TypeBuilder, string, bool)

Adds a property to the type without implementations of get or set.

Declaration
public static PropertyBuildInfo AddProperty<T>(this TypeBuilder tb, string name, bool writable)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

bool writable

true to create a property that contains a write accessor (set); false to omit the write accessor.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

Type Parameters
Name Description
T

Type of the new property.

Remarks

The generated property requires that the accessors be implemented before the type is built.

| Edit this page View Source

AddProperty<T>(TypeBuilder, string, bool, MemberAccess)

Adds a property to the type without implementations of get or set.

Declaration
public static PropertyBuildInfo AddProperty<T>(this TypeBuilder tb, string name, bool writable, MemberAccess access)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

bool writable

true to create a property that contains a write accessor (set); false to omit the write accessor.

MemberAccess access

Access level of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

Type Parameters
Name Description
T

Type of the new property.

Remarks

The generated property requires that the accessors be implemented before the type is built.

| Edit this page View Source

AddProperty<T>(TypeBuilder, string, bool, MemberAccess, bool)

Adds a property to the type without get or set implementations.

Declaration
public static PropertyBuildInfo AddProperty<T>(this TypeBuilder tb, string name, bool writable, MemberAccess access, bool @virtual)
Parameters
Type Name Description
TypeBuilder tb

Type constructor in which to create the property.

string name

Name of the new property.

bool writable

true to include a write accessor (set); false to omit it.

MemberAccess access

Access level of the new property.

bool virtual

If true, the property will be virtual and can be overridden in derived classes.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the constructed property.

Type Parameters
Name Description
T

Type of the new property.

Remarks

The generated property requires that the accessors be implemented before building the type.

| Edit this page View Source

AddPublicConstructor(TypeBuilder)

Explicitly inserts a public parameterless constructor into the type.

Declaration
public static ILGenerator AddPublicConstructor(this TypeBuilder tb)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which the new constructor will be defined.

Returns
Type Description
ILGenerator

An ILGenerator that allows defining the constructor's instructions.

| Edit this page View Source

AddPublicConstructor(TypeBuilder, params Type[])

Explicitly inserts a public constructor into the type, specifying the required arguments.

Declaration
public static ILGenerator AddPublicConstructor(this TypeBuilder tb, params Type[] arguments)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which the new constructor will be defined.

Type[] arguments

Array of types of arguments accepted by the new constructor.

Returns
Type Description
ILGenerator

An ILGenerator that allows defining the constructor's instructions.

| Edit this page View Source

AddWriteOnlyProperty(TypeBuilder, string, Type)

Adds a public write‑only property to the type.

Declaration
public static PropertyBuildInfo AddWriteOnlyProperty(this TypeBuilder tb, string name, Type type)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Type type

Type of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

| Edit this page View Source

AddWriteOnlyProperty(TypeBuilder, string, Type, bool)

Adds a public write‑only property to the type.

Declaration
public static PropertyBuildInfo AddWriteOnlyProperty(this TypeBuilder tb, string name, Type type, bool @virtual)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Type type

Type of the new property.

bool virtual

If set to true, the property will be declared virtual, allowing it to be overridden in a derived class.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

| Edit this page View Source

AddWriteOnlyProperty(TypeBuilder, string, Type, MemberAccess)

Adds a write‑only property to the type.

Declaration
public static PropertyBuildInfo AddWriteOnlyProperty(this TypeBuilder tb, string name, Type type, MemberAccess access)
Parameters
Type Name Description
TypeBuilder tb

Type builder in which to create the new property.

string name

Name of the new property.

Type type

Type of the new property.

MemberAccess access

Access level of the new property.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

| Edit this page View Source

AddWriteOnlyProperty(TypeBuilder, string, Type, MemberAccess, bool)

Adds a write‑only property to the type.

Declaration
public static PropertyBuildInfo AddWriteOnlyProperty(this TypeBuilder tb, string name, Type type, MemberAccess access, bool @virtual)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which the new property will be created.

string name

Name of the new property.

Type type

Type of the new property.

MemberAccess access

Access level of the new property.

bool virtual

If set to true, the property is defined as virtual, so it can be overridden in a derived class.

Returns
Type Description
PropertyBuildInfo

A PropertyBuildInfo that contains information about the property that has been built.

| Edit this page View Source

DefineMethod<TResult>(TypeBuilder, string, params Type[])

Defines a method that returns a specified type.

Declaration
public static MethodBuilder DefineMethod<TResult>(this TypeBuilder tb, string name, params Type[] parameterTypes)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which the new method will be created.

string name

Name of the new method.

Type[] parameterTypes

Types of the parameters accepted by the method.

Returns
Type Description
MethodBuilder

A MethodBuilder with which the method can be defined.

Type Parameters
Name Description
TResult

Result type returned by the method.

| Edit this page View Source

DefineVoidMethod(TypeBuilder, string, params Type[])

Defines a method that returns no value.

Declaration
public static MethodBuilder DefineVoidMethod(this TypeBuilder tb, string name, params Type[] parameterTypes)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which the new method will be created.

string name

Name of the new method.

Type[] parameterTypes

Type of the parameters accepted by the method.

Returns
Type Description
MethodBuilder

A MethodBuilder with which the method can be defined.

| Edit this page View Source

ExplicitImplementMethod(TypeBuilder, MethodInfo)

Explicitly implements an abstract method.

Declaration
public static MethodBuildInfo ExplicitImplementMethod(this TypeBuilder tb, MethodInfo method)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder in which the abstract method will be explicitly implemented.

MethodInfo method

Abstract method to implement. The specified TypeBuilder must implement the interface in which the method is defined.

Returns
Type Description
MethodBuildInfo

A MethodBuildInfo that contains information about the method that has been explicitly implemented.

Exceptions
Type Condition
InvalidOperationException

Thrown if tb does not implement or inherit the interface in which method is defined, or if method is not a member defined in an interface.

| Edit this page View Source

New(TypeBuilder)

Initializes a new instance of the specified runtime type.

Declaration
public static object New(this TypeBuilder tb)
Parameters
Type Name Description
TypeBuilder tb

TypeBuilder from which to instantiate a new object.

Returns
Type Description
object

The new instance of the specified type.

| Edit this page View Source

Overridable(TypeBuilder, string, params Type[])

Determines whether the specified method can be overridden.

Declaration
public static bool? Overridable(this TypeBuilder tb, string method, params Type[] args)
Parameters
Type Name Description
TypeBuilder tb

Type constructor on which to perform the query.

string method

Name of the method to search for.

Type[] args

Types of the method's arguments.

Returns
Type Description
bool?

true if the method can be overridden; false otherwise; or null if the method does not exist in the base class.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX