TypeBuilder.DefineField 方法

定義

將新欄位加入動態類型中。

多載

DefineField(String, Type, FieldAttributes)

將新欄位加入類型,指定其名稱、屬性和欄位類型。

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

將新欄位加入此類型,並指定其名稱、屬性、欄位類型和自訂修飾詞。

DefineField(String, Type, FieldAttributes)

來源:
TypeBuilder.cs
來源:
TypeBuilder.cs
來源:
TypeBuilder.cs

將新欄位加入類型,指定其名稱、屬性和欄位類型。

C#
public System.Reflection.Emit.FieldBuilder DefineField(string fieldName, Type type, System.Reflection.FieldAttributes attributes);

參數

fieldName
String

欄位的名稱。 fieldName 不能包含內嵌的 null。

type
Type

欄位的型別。

attributes
FieldAttributes

欄位的屬性。

傳回

定義的欄位。

例外狀況

fieldName 的長度為零。

-或-

type 為 System.Void。

-或-

為這個欄位的父類別指定了總大小。

fieldNamenull

先前使用 CreateType() 建立的類型。

適用於

.NET 10 及其他版本
產品 版本
.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, 10
.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

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

來源:
TypeBuilder.cs
來源:
TypeBuilder.cs
來源:
TypeBuilder.cs

將新欄位加入此類型,並指定其名稱、屬性、欄位類型和自訂修飾詞。

C#
public System.Reflection.Emit.FieldBuilder DefineField(string fieldName, Type type, Type[]? requiredCustomModifiers, Type[]? optionalCustomModifiers, System.Reflection.FieldAttributes attributes);
C#
public System.Reflection.Emit.FieldBuilder DefineField(string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, System.Reflection.FieldAttributes attributes);

參數

fieldName
String

欄位的名稱。 fieldName 不能包含內嵌的 null。

type
Type

欄位的型別。

requiredCustomModifiers
Type[]

類型陣列,代表欄位的必要自訂修飾詞,例如 IsConstModifier

optionalCustomModifiers
Type[]

類型陣列,代表欄位的選擇性自訂修飾詞,例如 IsConstModifier

attributes
FieldAttributes

欄位的屬性。

傳回

定義的欄位。

例外狀況

fieldName 的長度為零。

-或-

type 為 System.Void。

-或-

為這個欄位的父類別指定了總大小。

fieldNamenull

先前使用 CreateType() 建立的類型。

備註

這個多載是提供給Managed編譯程式的設計工具。

適用於

.NET 10 及其他版本
產品 版本
.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, 10
.NET Framework 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