TypeBuilder.DefineField 方法

定义

将新字段添加到动态类型。

重载

DefineField(String, Type, FieldAttributes)

将新字段添加到该类型,其名称、属性和字段类型已给定。

DefineField(String, Type, Type[], Type[], FieldAttributes)

将新字段添加到该类型,其名称、属性、字段类型和自定义修饰符已给定。

DefineField(String, Type, FieldAttributes)

将新字段添加到该类型,其名称、属性和字段类型已给定。

public:
 System::Reflection::Emit::FieldBuilder ^ DefineField(System::String ^ fieldName, Type ^ type, System::Reflection::FieldAttributes attributes);
public System.Reflection.Emit.FieldBuilder DefineField (string fieldName, Type type, System.Reflection.FieldAttributes attributes);
member this.DefineField : string * Type * System.Reflection.FieldAttributes -> System.Reflection.Emit.FieldBuilder
Public Function DefineField (fieldName As String, type As Type, attributes As FieldAttributes) As FieldBuilder

参数

fieldName
String

字段的名称。 fieldName 不能包含嵌入的 null。

type
Type

字段的类型。

attributes
FieldAttributes

字段的属性。

返回

FieldBuilder

已定义的字段。

例外

fieldName 的长度为零。

  • 或 - type 是 System.Void。

  • 或 - 为此字段的父类指定了总大小。

fieldNamenull

该类型是以前使用 CreateType() 创建的。

适用于

DefineField(String, Type, Type[], Type[], FieldAttributes)

将新字段添加到该类型,其名称、属性、字段类型和自定义修饰符已给定。

public:
 System::Reflection::Emit::FieldBuilder ^ DefineField(System::String ^ fieldName, Type ^ type, cli::array <Type ^> ^ requiredCustomModifiers, cli::array <Type ^> ^ optionalCustomModifiers, System::Reflection::FieldAttributes attributes);
public System.Reflection.Emit.FieldBuilder DefineField (string fieldName, Type type, Type[]? requiredCustomModifiers, Type[]? optionalCustomModifiers, System.Reflection.FieldAttributes attributes);
public System.Reflection.Emit.FieldBuilder DefineField (string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, System.Reflection.FieldAttributes attributes);
member this.DefineField : string * Type * Type[] * Type[] * System.Reflection.FieldAttributes -> System.Reflection.Emit.FieldBuilder
Public Function DefineField (fieldName As String, type As Type, requiredCustomModifiers As Type(), optionalCustomModifiers As Type(), attributes As FieldAttributes) As FieldBuilder

参数

fieldName
String

字段的名称。 fieldName 不能包含嵌入的 null。

type
Type

字段的类型。

requiredCustomModifiers
Type[]

一个类型数组,表示字段所必需的自定义修饰符,如 IsConstModifier

optionalCustomModifiers
Type[]

一个类型数组,表示字段可选的自定义修饰符,如 IsConstModifier

attributes
FieldAttributes

字段的属性。

返回

FieldBuilder

已定义的字段。

例外

fieldName 的长度为零。

  • 或 - type 是 System.Void。

  • 或 - 为此字段的父类指定了总大小。

fieldNamenull

该类型是以前使用 CreateType() 创建的。

注解

此重载提供给托管编译器的设计器。

适用于