TypeBuilder.DefineField Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a new field to the dynamic type.
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) |
Adds a new field to the type, with the given name, attributes, field type, and custom modifiers. |
- Source:
- TypeBuilder.cs
- Source:
- TypeBuilder.cs
- Source:
- TypeBuilder.cs
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
Public Function DefineField (fieldName As String, type As Type, attributes As FieldAttributes) As FieldBuilder
Parameters
- fieldName
- String
The name of the field. fieldName
cannot contain embedded nulls.
- type
- Type
The type of the field.
- attributes
- FieldAttributes
The attributes of the field.
Returns
The defined field.
Exceptions
The length of fieldName
is zero.
-or-
type
is System.Void.
-or-
A total size was specified for the parent class of this field.
fieldName
is null
.
The type was previously created using CreateType().
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 |
- Source:
- TypeBuilder.cs
- Source:
- TypeBuilder.cs
- Source:
- TypeBuilder.cs
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);
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
Parameters
- fieldName
- String
The name of the field. fieldName
cannot contain embedded nulls.
- type
- Type
The type of the field.
- requiredCustomModifiers
- Type[]
An array of types representing the required custom modifiers for the field, such as IsConstModifier.
- optionalCustomModifiers
- Type[]
An array of types representing the optional custom modifiers for the field, such as IsConstModifier.
- attributes
- FieldAttributes
The attributes of the field.
Returns
The defined field.
Exceptions
The length of fieldName
is zero.
-or-
type
is System.Void.
-or-
A total size was specified for the parent class of this field.
fieldName
is null
.
The type was previously created using CreateType().
Remarks
This overload is provided for designers of managed compilers.
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 | 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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: