Share via


FieldOffsetAttribute Kelas

Definisi

Menunjukkan posisi fisik bidang dalam representasi kelas atau struktur yang tidak dikelola.

public ref class FieldOffsetAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Field, Inherited=false)]
public sealed class FieldOffsetAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class FieldOffsetAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field, Inherited=false)>]
type FieldOffsetAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Field, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FieldOffsetAttribute = class
    inherit Attribute
Public NotInheritable Class FieldOffsetAttribute
Inherits Attribute
Warisan
FieldOffsetAttribute
Atribut

Contoh

Contoh berikut menunjukkan cara menerapkan FieldOffsetAttribute ke anggota struktur atau kelas dengan tata letak eksplisit.


[StructLayout(LayoutKind::Explicit)]
public ref class SYSTEM_INFO
{
public:

   [FieldOffset(0)]
   UInt64 OemId;

   [FieldOffset(8)]
   UInt64 PageSize;

   [FieldOffset(24)]
   UInt64 ActiveProcessorMask;

   [FieldOffset(32)]
   UInt64 NumberOfProcessors;

   [FieldOffset(40)]
   UInt64 ProcessorType;
};
[StructLayout(LayoutKind.Explicit)]
public struct SYSTEM_INFO
{
[FieldOffset(0)] public ulong OemId;
[FieldOffset(8)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(24)] public ulong NumberOfProcessors;
[FieldOffset(32)] public ulong ProcessorType;
}
<StructLayout(LayoutKind.Explicit)> _
Public Class SYSTEM_INFO
    <FieldOffset(0)> Private OemId As System.UInt64
    <FieldOffset(8)> Private PageSize As System.UInt64
    <FieldOffset(16)> Private ActiveProcessorMask As System.UInt64
    <FieldOffset(24)> Private NumberOfProcessors As System.UInt64
    <FieldOffset(32)> Private ProcessorType As System.UInt64
End Class

Untuk contoh yang lebih besar, lihat System.Runtime.InteropServices.StructLayoutAttribute kelas .

Keterangan

Anda dapat menerapkan atribut ini ke bidang.

Atribut ini digunakan ketika System.Runtime.InteropServices.StructLayoutAttribute, dengan LayoutKind.Explicit diteruskan ke konstruktornya, diterapkan ke kelas atau struktur untuk menentukan offset setiap anggota non-atau static konstan dalam representasi tidak terkelola dari kelas atau struktur tersebut.

Konstruktor

FieldOffsetAttribute(Int32)

Menginisialisasi instans FieldOffsetAttribute baru kelas dengan offset dalam struktur ke awal bidang.

Properti

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)
Value

Mendapatkan offset dari awal struktur ke awal bidang.

Metode

Equals(Object)

Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
GetHashCode()

Mengembalikan kode hash untuk instans ini.

(Diperoleh dari Attribute)
GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga