See Also: FieldOffsetAttribute Members
System.Object
System.Attribute
System.Runtime.InteropServices.FieldOffsetAttribute
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
The target objects for this attribute are non-static fields of classes and structures qualified with the System.Runtime.InteropServices.StructLayoutAttribute set to LayoutKind.Explicit . All non-static fields within an object with an explicit layout are required to have this attribute. No static or constant fields within an object with explicit layout are allowed to have this attribute.
The physical layout of the data members of a class or structure is automatically arranged in managed memory. When a managed object is passed as an argument to unmanaged code, the system creates its unmanaged representation. System.Runtime.InteropServices.StructLayoutAttribute provides explicit control over this unmanaged representation. System.Runtime.InteropServices.FieldOffsetAttribute indicates the offset of a target data member within the unmanaged representation of a class or structure.
If System.Runtime.InteropServices.FieldOffsetAttribute instances on target fields of an exported object are set to overlap each other, one field is overwritten by another field. For example, if an integer field has the System.Runtime.InteropServices.FieldOffsetAttribute set to 4, and another integer field has the System.Runtime.InteropServices.FieldOffsetAttribute set to 6, the last two bytes of the unmanaged representation of the first integer overlap the first two bytes of the second integer. In such a situation writing to one of the fields might corrupt the data in the other.
Note: See the System.Runtime.InteropServices.StructLayoutAttribute class overview for an example that uses System.Runtime.InteropServices.FieldOffsetAttribute.Compilers are required to not preserve this type in metadata as a custom attribute. Instead, compilers are required to emit it directly in the file format, as described in Partition II of the CLI Specification. Metadata consumers, such as the Reflection API, are required to retrieve this data from the file format and return it as if it were a custom attribute.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0