Type.IsLayoutSequential Özellik

Tanım

Geçerli türdeki alanların, tanımlandıkları veya meta verilere yayınlandıkları sırada sıralı olarak düzenlendiğini gösteren 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

Boolean

trueAttributesgeçerli türün özelliği içeriyorsa SequentialLayout ; Aksi durumda, false .

Uygulamalar

Örnekler

Aşağıdaki örnek, LayoutKind.Sequential sınıfında numaralandırma değerinin ayarlandığı bir sınıfın örneğini oluşturur StructLayoutAttribute , IsLayoutSequential özelliği denetler ve sonucu görüntüler.

#using <System.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;
ref class MyTypeSequential1{};


[StructLayoutAttribute(LayoutKind::Sequential)]
ref class MyTypeSequential2{};

int main()
{
   try
   {
      
      // Create an instance of myTypeSeq1.
      MyTypeSequential1^ myObj1 = gcnew MyTypeSequential1;
      
      // 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 = gcnew MyTypeSequential2;
      
      // 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 );
   }

}
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);
        }
    }
}
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 olarak sunulmaktadır. Alternatif olarak, TypeAttributes.LayoutMask tür Düzen özniteliklerini seçmek için sabit listesi değerini kullanabilir ve sonra ayarlanmış olup olmadığını test edebilirsiniz TypeAttributes.SequentialLayout . TypeAttributes.AutoLayout, TypeAttributes.ExplicitLayout , Ve TypeAttributes.SequentialLayout sabit listesi değerleri, tür alanlarının bellekte nasıl düzenlendiğini belirtir.

Dinamik türler için, TypeAttributes.SequentialLayout türünü ne zaman oluşturacağınız belirtebilirsiniz. Kod içinde, StructLayoutAttribute LayoutKind.Sequential düzeni sıralı olacak şekilde belirtmek için, türü numaralandırma değeri olan özniteliğini uygulayın.

Not

GetCustomAttributes StructLayoutAttribute Bir türe uygulanıp uygulanmadığını anlamak için yöntemini kullanamazsınız.

Daha fazla bilgi için, "Bölüm II: meta veri tanımı ve semantiği" ortak dil altyapısı (CLı) belgelerinin belirtiminin 9.1.2 bölümüne bakın. Belgeler çevrimiçi olarak kullanılabilir; Ecma International web sitesinde bkz. MSDN ve standart ECMA-335-ortak dil altyapısı (CLI) üzerinde ecma C# ve ortak dil altyapısı standartları .

Geçerli, Type oluşturulmuş bir genel türü temsil ediyorsa, bu özellik türün oluşturulduğu genel tür tanımına uygulanır. örneğin, geçerli Type temsil ediyorsa MyGenericType<int> ( MyGenericType(Of Integer) Visual Basic), bu özelliğin değeri tarafından belirlenir MyGenericType<T> .

Geçerli, Type genel bir türün veya genel yöntemin tanımındaki bir tür parametresini temsil ediyorsa, bu özellik her zaman döndürülür false .

Şunlara uygulanır

Ayrıca bkz.