Type.IsLayoutSequential 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 berurutan, dalam urutan yang ditentukan atau dipancarkan ke metadata.
public:
property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean
Nilai Properti
true
Attributes jika properti dari jenis saat ini mencakup SequentialLayout; jika tidak, false.
Penerapan
Contoh
Contoh berikut membuat instans kelas yang LayoutKind.Sequential nilai enumerasinya StructLayoutAttribute telah diatur, memeriksa IsLayoutSequential properti, dan menampilkan hasilnya.
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
class MyTypeSequential1
{
}
[StructLayoutAttribute(LayoutKind.Sequential)]
class MyTypeSequential2
{
public static void Main(string []args)
{
try
{
// Create an instance of myTypeSeq1.
MyTypeSequential1 myObj1 = new MyTypeSequential1();
Type myTypeObj1 = myObj1.GetType();
// Check for and display the SequentialLayout attribute.
Console.WriteLine("\nThe object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential);
// Create an instance of 'myTypeSeq2' class.
MyTypeSequential2 myObj2 = new MyTypeSequential2();
Type myTypeObj2 = myObj2.GetType();
// Check for and display the SequentialLayout attribute.
Console.WriteLine("\nThe object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential);
}
catch(Exception e)
{
Console.WriteLine("\nAn exception occurred: {0}", e.Message);
}
}
}
open System.Runtime.InteropServices
type MyTypeSequential1 = struct end
[<StructLayoutAttribute(LayoutKind.Sequential)>]
type MyTypeSequential2 = struct end
try
// Create an instance of myTypeSeq1.
let myObj1 = MyTypeSequential1()
let myTypeObj1 = myObj1.GetType()
// Check for and display the SequentialLayout attribute.
printfn $"\nThe object myObj1 has IsLayoutSequential: {myTypeObj1.IsLayoutSequential}."
// Create an instance of 'myTypeSeq2' class.
let myObj2 = MyTypeSequential2()
let myTypeObj2 = myObj2.GetType()
// Check for and display the SequentialLayout attribute.
printfn $"\nThe object myObj2 has IsLayoutSequential: {myTypeObj2.IsLayoutSequential}."
with e ->
printfn $"\nAn exception occurred: {e.Message}"
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Class MyTypeSequential1
End Class
<StructLayoutAttribute(LayoutKind.Sequential)> Class MyTypeSequential2
Public Shared Sub Main()
Try
' Create an instance of MyTypeSequential1.
Dim myObj1 As New MyTypeSequential1()
Dim myTypeObj1 As Type = myObj1.GetType()
' Check for and display the SequentialLayout attribute.
Console.WriteLine(ControlChars.Cr + "The object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential.ToString())
' Create an instance of MyTypeSequential2.
Dim myObj2 As New MyTypeSequential2()
Dim myTypeObj2 As Type = myObj2.GetType()
' Check for and display the SequentialLayout attribute.
Console.WriteLine(ControlChars.Cr + "The object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential.ToString())
Catch e As Exception
Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
End Try
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.SequentialLayout diatur. Nilai TypeAttributes.AutoLayoutenumerasi , TypeAttributes.ExplicitLayout, dan TypeAttributes.SequentialLayout menunjukkan cara bidang jenis ditata dalam memori.
Untuk jenis dinamis, Anda dapat menentukan TypeAttributes.SequentialLayout kapan Anda membuat jenis. Dalam kode, terapkan StructLayoutAttribute atribut dengan LayoutKind.Sequential nilai enumerasi ke jenis , untuk menentukan tata letak tersebut berurutan.
Nota
Anda tidak dapat menggunakan GetCustomAttributes metode untuk menentukan apakah StructLayoutAttribute telah diterapkan ke tipe.
Untuk informasi selengkapnya, lihat bagian 9.1.2 spesifikasi untuk dokumentasi Common Language Infrastructure (CLI), "Partisi II: Definisi Metadata dan Semantik".
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.