Type.IsLayoutSequential Właściwość

Definicja

Pobiera wartość wskazującą, czy pola bieżącego typu są ułożone sekwencyjnie w kolejności, w których zostały zdefiniowane lub emitowane do metadanych.

public:
 property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean

Wartość właściwości

Boolean

true Jeśli właściwość Attributes bieżącego typu zawiera wartość SequentialLayout ; w przeciwnym razie wartość false .

Implementuje

Przykłady

Poniższy przykład tworzy wystąpienie klasy, dla której ustawiono wartość wyliczenia w klasie, sprawdza właściwość LayoutKind.Sequential StructLayoutAttribute i wyświetla IsLayoutSequential wynik.

#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

Uwagi

Ta właściwość jest dostarczana jako udogodnienie. Alternatywnie można użyć wartości wyliczenia, aby wybrać atrybuty układu typu, a następnie TypeAttributes.LayoutMask przetestować, TypeAttributes.SequentialLayout czy jest ustawiona. Wartości wyliczenia , i wskazują układ pól typu TypeAttributes.AutoLayout TypeAttributes.ExplicitLayout w TypeAttributes.SequentialLayout pamięci.

W przypadku typów dynamicznych można TypeAttributes.SequentialLayout określić, kiedy tworzysz typ. W kodzie zastosuj atrybut StructLayoutAttribute z LayoutKind.Sequential wartością wyliczenia do typu , aby określić, że układ jest sekwencyjny.

Uwaga

Nie można użyć metody , aby określić, czy metoda GetCustomAttributes została StructLayoutAttribute zastosowana do typu.

Aby uzyskać więcej informacji, zobacz sekcję 9.1.2 specyfikacji dokumentacji interfejsu Common Language Infrastructure (CLI), "Partition II: Metadata Definition and Semantics" (Partycja II: definicja metadanych i semantyka). Dokumentacja jest dostępna online. Zobacz ecma C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) (Standardy ECMA C# i standardu standardowego ECMA-335 — Common Language Infrastructure cli) w witrynie internetowej Ecma International.

Jeśli bieżący reprezentuje skonstruowany typ ogólny, ta właściwość ma zastosowanie do definicji typu ogólnego, z Type której został skonstruowany typ. Jeśli na przykład bieżący obiekt reprezentuje wartość ( w Visual Basic), wartość Type tej właściwości jest MyGenericType<int> MyGenericType(Of Integer) określana przez wartość MyGenericType<T> .

Jeśli bieżąca wartość reprezentuje parametr typu w definicji typu ogólnego lub metody ogólnej, ta właściwość Type zawsze zwraca wartość false .

Dotyczy

Zobacz też