Type.IsLayoutSequential Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Geçerli türdeki alanların meta verilerde tanımlandığı veya yayıldığı sırada sıralı olarak düzenlendiğini belirten bir değer alır.
public:
property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean
Özellik Değeri
true
Attributes geçerli türün özelliği içeriyorsa SequentialLayout; değilse, false.
Uygulamalar
Örnekler
Aşağıdaki örnek, sınıfındaki numaralandırma değerinin LayoutKind.SequentialStructLayoutAttribute ayarlandığı, özelliği denetlediği IsLayoutSequential ve sonucu görüntülediği bir sınıfın örneğini oluşturur.
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
Açıklamalar
Bu özellik kolaylık sağlamak için sağlanır. Alternatif olarak, tür düzeni özniteliklerini seçmek ve ardından ayarlanıp ayarlanmadığını TypeAttributes.SequentialLayout test etmek için numaralandırma değerini kullanabilirsinizTypeAttributes.LayoutMask. TypeAttributes.AutoLayout, TypeAttributes.ExplicitLayoutve TypeAttributes.SequentialLayout numaralandırma değerleri, tür alanlarının bellekte nasıl yerleştirileceğine işaret eder.
Dinamik türler için türü oluşturduğunuzda belirtebilirsiniz TypeAttributes.SequentialLayout . Kodda, düzenin StructLayoutAttributeLayoutKind.Sequential sıralı olduğunu belirtmek için türüne numaralandırma değeriyle özniteliğini uygulayın.
Uyarı
bir türe GetCustomAttributes uygulanıp uygulanmadığını StructLayoutAttribute belirlemek için yöntemini kullanamazsınız.
Daha fazla bilgi için Ortak Dil Altyapısı (CLI) belgelerinin belirtiminin 9.1.2. bölümüne bakın: "Bölüm II: Meta Veri Tanımı ve Semantik".
Geçerli Type , bir genel tür oluşturulduysa, bu özellik türün oluşturulduğu genel tür tanımına uygulanır. Örneğin, geçerli Type değeri (MyGenericType(Of Integer) Visual Basic'te) temsil ederse MyGenericType<int> , bu özelliğin değeri tarafından MyGenericType<T>belirlenir.
Geçerli Type , genel bir tür veya genel yöntemin tanımında tür parametresini temsil ederse, bu özellik her zaman döndürür false.