Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Defining a Field with Reflection Emit

Defining a Field with Reflection Emit

A field is defined as a type member using the TypeBuilder.DefineField method. The DefineField method requires the caller to specify the field name, the field type, and the field attributes (using the FieldAttributes enumeration). DefineField returns a FieldBuilder.

FieldBuilder.SetOffset defines field layout. FieldBuilder.SetMarshal defines how a field is marshaled. FieldBuilder.SetConstant defines the default value of a field.

A field can also reference data in the .sdata section of the portable executable (PE) file. Fields representing initialized data are defined using ModuleBuilder.DefineInitializedData. Fields representing uninitialized data are defined using ModuleBuilder.DefineUninitializedData.

  • Static fields are specified using the FieldAttributes.Static attribute.

  • Fields that can be initialized but not subsequently written to are specified using the FieldAttributes.InitOnly attribute.

  • Fields that are compile-time constants are specified using the FieldAttributes.Literal attribute.

  • There are several attributes that determine field visibility. See the description of the FieldAttributes enumeration.

Community Additions

© 2015 Microsoft