TypeBuilder.DefineField 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將新欄位加入動態類型中。
DefineField(String, Type, FieldAttributes) |
將新欄位加入類型,指定其名稱、屬性和欄位類型。 |
DefineField(String, Type, Type[], Type[], FieldAttributes) |
將新欄位加入此類型,並指定其名稱、屬性、欄位類型和自訂修飾詞。 |
將新欄位加入類型,指定其名稱、屬性和欄位類型。
public:
System::Reflection::Emit::FieldBuilder ^ DefineField(System::String ^ fieldName, Type ^ type, System::Reflection::FieldAttributes attributes);
C#
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
欄位的屬性。
傳回
定義的欄位。
例外狀況
fieldName
為 null
。
先前使用 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 |
將新欄位加入此類型,並指定其名稱、屬性、欄位類型和自訂修飾詞。
public:
System::Reflection::Emit::FieldBuilder ^ DefineField(System::String ^ fieldName, Type ^ type, cli::array <Type ^> ^ requiredCustomModifiers, cli::array <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);
C#
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
欄位的屬性。
傳回
定義的欄位。
例外狀況
fieldName
為 null
。
先前使用 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 |