TypeBuilder.DefineNestedType Method

Definition

Defines a nested type.

Overloads

DefineNestedType(String, TypeAttributes, Type, Type[])

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

DefineNestedType(String, TypeAttributes, Type, PackingSize, Int32)

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

DefineNestedType(String, TypeAttributes, Type, PackingSize)

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

DefineNestedType(String)

Defines a nested type, given its name.

DefineNestedType(String, TypeAttributes, Type)

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

DefineNestedType(String, TypeAttributes)

Defines a nested type, given its name and attributes.

DefineNestedType(String, TypeAttributes, Type, Int32)

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

DefineNestedType(String, TypeAttributes, Type, Type[])

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

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

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type? parent, Type[]? interfaces);
public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, Type[] interfaces);
[System.Runtime.InteropServices.ComVisible(true)]
public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, Type[] interfaces);

Parameters

name
String

The short name of the type. name cannot contain embedded nulls.

attr
TypeAttributes

The attributes of the type.

parent
Type

The type that the nested type extends.

interfaces
Type[]

The interfaces that the nested type implements.

Returns

The defined nested type.

Attributes

Exceptions

The nested attribute is not specified.

-or-

This type is sealed.

-or-

This type is an array.

-or-

This type is an interface, but the nested type is not an interface.

-or-

The length of name is zero or greater than 1023.

-or-

This operation would create a type with a duplicate FullName in the current assembly.

name is null.

-or-

An element of the interfaces array is null.

Remarks

This method can be used to create nested types even after the CreateType method has been called on the enclosing type.

The nested type needs to be complete before you can reflect on it using GetMembers, GetNestedType, or GetNestedTypes.

See the description of CreateType for the order in which nested types and nesting types should be completed.

A duplicate name is not necessarily created if name is identical to the name of a previously defined type or nested type. To be duplicates, the full names must be the same, including the namespace and all nesting types.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

DefineNestedType(String, TypeAttributes, Type, PackingSize, Int32)

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

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

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type? parent, System.Reflection.Emit.PackingSize packSize, int typeSize);
public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, System.Reflection.Emit.PackingSize packSize, int typeSize);

Parameters

name
String

The short name of the type. name cannot contain embedded null values.

attr
TypeAttributes

The attributes of the type.

parent
Type

The type that the nested type extends.

packSize
PackingSize

The packing size of the type.

typeSize
Int32

The total size of the type.

Returns

The defined nested type.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

DefineNestedType(String, TypeAttributes, Type, PackingSize)

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

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

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type? parent, System.Reflection.Emit.PackingSize packSize);
public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, System.Reflection.Emit.PackingSize packSize);

Parameters

name
String

The short name of the type. name cannot contain embedded nulls.

attr
TypeAttributes

The attributes of the type.

parent
Type

The type that the nested type extends.

packSize
PackingSize

The packing size of the type.

Returns

The defined nested type.

Exceptions

The nested attribute is not specified.

-or-

This type is sealed.

-or-

This type is an array.

-or-

This type is an interface, but the nested type is not an interface.

-or-

The length of name is zero or greater than 1023.

-or-

This operation would create a type with a duplicate FullName in the current assembly.

name is null.

Remarks

This method can be used to create nested types even after the CreateType method has been called on the enclosing type.

The nested type needs to be complete before you can reflect on it using GetMembers, GetNestedType, or GetNestedTypes.

See the description of CreateType for the order in which nested types and nesting types should be completed.

A duplicate name is not necessarily created if name is identical to the name of a previously defined type or nested type. To be duplicates, the full names must be the same, including the namespace and all nesting types.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

DefineNestedType(String)

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

Defines a nested type, given its name.

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name);

Parameters

name
String

The short name of the type. name cannot contain embedded nulls.

Returns

The defined nested type.

Exceptions

Length of name is zero or greater than 1023.

-or-

This operation would create a type with a duplicate FullName in the current assembly.

name is null.

Remarks

This method can be used to create nested types even after the CreateType method has been called on the enclosing type.

The nested type needs to be complete before you can reflect on it using GetMembers, GetNestedType, or GetNestedTypes.

See the description of CreateType for the order in which nested types and nesting types should be completed.

A duplicate name is not necessarily created if name is identical to the name of a previously defined type or nested type. To be duplicates, the full names must be the same, including the namespace and all nesting types.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

DefineNestedType(String, TypeAttributes, Type)

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

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

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type? parent);
public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent);

Parameters

name
String

The short name of the type. name cannot contain embedded nulls.

attr
TypeAttributes

The attributes of the type.

parent
Type

The type that the nested type extends.

Returns

The defined nested type.

Exceptions

The nested attribute is not specified.

-or-

This type is sealed.

-or-

This type is an array.

-or-

This type is an interface, but the nested type is not an interface.

-or-

The length of name is zero or greater than 1023.

-or-

This operation would create a type with a duplicate FullName in the current assembly.

name is null.

Remarks

This method can be used to create nested types even after the CreateType method has been called on the enclosing type.

The nested type needs to be complete before you can reflect on it using GetMembers, GetNestedType, or GetNestedTypes.

See the description of CreateType for the order in which nested types and nesting types should be completed.

A duplicate name is not necessarily created if name is identical to the name of a previously defined type or nested type. To be duplicates, the full names must be the same, including the namespace and all nesting types.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

DefineNestedType(String, TypeAttributes)

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

Defines a nested type, given its name and attributes.

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr);

Parameters

name
String

The short name of the type. name cannot contain embedded nulls.

attr
TypeAttributes

The attributes of the type.

Returns

The defined nested type.

Exceptions

The nested attribute is not specified.

-or-

This type is sealed.

-or-

This type is an array.

-or-

This type is an interface, but the nested type is not an interface.

-or-

The length of name is zero or greater than 1023.

-or-

This operation would create a type with a duplicate FullName in the current assembly.

name is null.

Remarks

This method can be used to create nested types even after the CreateType method has been called on the enclosing type.

The nested type needs to be complete before you can reflect on it using GetMembers, GetNestedType, or GetNestedTypes.

See the description of CreateType for the order in which nested types and nesting types should be completed.

A duplicate name is not necessarily created if name is identical to the name of a previously defined type or nested type. To be duplicates, the full names must be the same, including the namespace and all nesting types.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

DefineNestedType(String, TypeAttributes, Type, Int32)

Source:
TypeBuilder.cs
Source:
TypeBuilder.cs
Source:
TypeBuilder.cs

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

public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type? parent, int typeSize);
public System.Reflection.Emit.TypeBuilder DefineNestedType (string name, System.Reflection.TypeAttributes attr, Type parent, int typeSize);

Parameters

name
String

The short name of the type. name cannot contain embedded nulls.

attr
TypeAttributes

The attributes of the type.

parent
Type

The type that the nested type extends.

typeSize
Int32

The total size of the type.

Returns

The defined nested type.

Exceptions

The nested attribute is not specified.

-or-

This type is sealed.

-or-

This type is an array.

-or-

This type is an interface, but the nested type is not an interface.

-or-

The length of name is zero or greater than 1023.

-or-

This operation would create a type with a duplicate FullName in the current assembly.

name is null.

Remarks

This method can be used to create nested types even after the CreateType method has been called on the enclosing type.

The nested type needs to be complete before you can reflect on it using GetMembers, GetNestedType, or GetNestedTypes.

See the description of CreateType for the order in which nested types and nesting types should be completed.

A duplicate name is not necessarily created if name is identical to the name of a previously defined type or nested type. To be duplicates, the full names must be the same, including the namespace and all nesting types.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1