Type.IsAutoLayout Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nilai yang menunjukkan apakah bidang jenis saat ini ditata secara otomatis oleh runtime bahasa umum.
public:
property bool IsAutoLayout { bool get(); };
public bool IsAutoLayout { get; }
member this.IsAutoLayout : bool
Public ReadOnly Property IsAutoLayout As Boolean
Nilai Properti
true
Attributes jika properti dari jenis saat ini mencakup AutoLayout; jika tidak, false.
Penerapan
Contoh
Contoh berikut membuat instans jenis dan menampilkan IsAutoLayout properti .
using System;
using System.Runtime.InteropServices;
// The Demo class is attributed as AutoLayout.
[StructLayoutAttribute(LayoutKind.Auto)]
public class Demo
{
}
public class Example
{
public static void Main()
{
// Create an instance of the Type class using the GetType method.
Type myType=typeof(Demo);
// Get and display the IsAutoLayout property of the
// Demoinstance.
Console.WriteLine("\nThe AutoLayout property for the Demo class is {0}.",
myType.IsAutoLayout);
}
}
open System.Runtime.InteropServices
// The Demo class is attributed as AutoLayout.
[<StructLayoutAttribute(LayoutKind.Auto)>]
type Demo = class end
// Create an instance of the Type class using the GetType method.
let myType = typeof<Demo>
// Get and display the IsAutoLayout property of the
// Demoinstance.
printfn $"\nThe AutoLayout property for the Demo class is {myType.IsAutoLayout}."
Imports System.Runtime.InteropServices
' The Demo class is has the AutoLayout attribute.
<StructLayoutAttribute(LayoutKind.Auto)> _
Public Class Demo
End Class
Public Class Example
Public Shared Sub Main()
' Get the Type object for the Demo class.
Dim myType As Type = GetType(Demo)
' Get and display the IsAutoLayout property of the
' Demo class.
Console.WriteLine("The AutoLayout property for the Demo class is '{0}'.", _
myType.IsAutoLayout.ToString())
End Sub
End Class
Keterangan
Properti ini disediakan sebagai kenyamanan. Atau, Anda dapat menggunakan TypeAttributes.LayoutMask nilai enumerasi untuk memilih atribut tata letak jenis, lalu menguji apakah TypeAttributes.AutoLayout diatur. Nilai TypeAttributes.AutoLayout,TypeAttributes.ExplicitLayout, dan TypeAttributes.SequentialLayout enumerasi menunjukkan cara bidang jenis ditata dalam memori.
Untuk jenis dinamis, Anda dapat menentukan TypeAttributes.AutoLayout kapan Anda membuat jenis. Dalam kode, terapkan StructLayoutAttribute atribut dengan LayoutKind.Auto nilai enumerasi ke jenis , untuk membiarkan runtime menentukan cara yang sesuai untuk menjabarkan kelas.
Nota
Anda tidak dapat menggunakan GetCustomAttributes metode untuk menentukan apakah StructLayoutAttribute telah diterapkan ke tipe.
Jika saat ini Type mewakili jenis generik yang dibangun, properti ini berlaku untuk definisi jenis generik tempat jenis dibuat. Misalnya, jika saat ini Type mewakili MyGenericType<int> (MyGenericType(Of Integer) dalam Visual Basic), nilai properti ini ditentukan oleh MyGenericType<T>.
Jika saat ini Type mewakili parameter jenis dalam definisi jenis generik atau metode generik, properti ini selalu mengembalikan false.