TypeBuilder.DefineField TypeBuilder.DefineField TypeBuilder.DefineField Method

定义

将新字段添加到动态类型。Adds a new field to the dynamic type.

重载

DefineField(String, Type, FieldAttributes) DefineField(String, Type, FieldAttributes) DefineField(String, Type, FieldAttributes)

将新字段添加到该类型,其名称、属性和字段类型已给定。Adds a new field to the type, with the given name, attributes, and field type.

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

将新字段添加到该类型,其名称、属性、字段类型和自定义修饰符已给定。Adds a new field to the type, with the given name, attributes, field type, and custom modifiers.

DefineField(String, Type, FieldAttributes) DefineField(String, Type, FieldAttributes) DefineField(String, Type, FieldAttributes)

将新字段添加到该类型,其名称、属性和字段类型已给定。Adds a new field to the type, with the given name, attributes, and field type.

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

参数

fieldName
String String String

字段的名称。The name of the field. fieldName 不能包含嵌入的 null。fieldName cannot contain embedded nulls.

type
Type Type Type

字段的类型The type of the field

attributes
FieldAttributes FieldAttributes FieldAttributes

字段的属性。The attributes of the field.

返回

已定义的字段。The defined field.

异常

fieldName 的长度为零。The length of fieldName is zero.

-or- type 是 System.Void。type is System.Void.

- 或 --or- 为此字段的父类指定了总大小。A total size was specified for the parent class of this field.

fieldNamenullfieldName is null.

该类型是以前使用 CreateType() 创建的。The type was previously created using CreateType().

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

将新字段添加到该类型,其名称、属性、字段类型和自定义修饰符已给定。Adds a new field to the type, with the given name, attributes, field type, and custom modifiers.

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);
member this.DefineField : string * Type * Type[] * Type[] * System.Reflection.FieldAttributes -> System.Reflection.Emit.FieldBuilder

参数

fieldName
String String String

字段的名称。The name of the field. fieldName 不能包含嵌入的 null。fieldName cannot contain embedded nulls.

type
Type Type Type

字段的类型The type of the field

requiredCustomModifiers
Type[]

一个类型数组,表示字段所必需的自定义修饰符,如 IsConstModifierAn array of types representing the required custom modifiers for the field, such as IsConstModifier.

optionalCustomModifiers
Type[]

一个类型数组,表示字段可选的自定义修饰符,如 IsConstModifierAn array of types representing the optional custom modifiers for the field, such as IsConstModifier.

attributes
FieldAttributes FieldAttributes FieldAttributes

字段的属性。The attributes of the field.

返回

已定义的字段。The defined field.

异常

fieldName 的长度为零。The length of fieldName is zero.

-or- type 是 System.Void。type is System.Void.

-or- 为此字段的父类指定了总大小。A total size was specified for the parent class of this field.

fieldNamenullfieldName is null.

该类型是以前使用 CreateType() 创建的。The type was previously created using CreateType().

注解

此重载是为托管编译器的设计器提供的。This overload is provided for designers of managed compilers.

适用于