Type.IsLayoutSequential Vlastnost

Definice

Získá hodnotu označující, zda pole aktuálního typu jsou rozloženy postupně v pořadí, v jakém byly definovány nebo generovány do metadat.

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

Hodnota vlastnosti

trueAttributes pokud vlastnost aktuálního typu zahrnuje SequentialLayout, jinak hodnota false.

Implementuje

Příklady

Následující příklad vytvoří instanci třídy, pro kterou LayoutKind.Sequential byla nastavena hodnota výčtu StructLayoutAttribute ve třídě, zkontroluje IsLayoutSequential vlastnost a zobrazí výsledek.

#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);
        }
    }
}
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

Poznámky

Tato vlastnost je k dispozici pro pohodlí. Alternativně můžete použít hodnotu výčtu TypeAttributes.LayoutMask k výběru atributů rozložení typu a poté otestovat, zda TypeAttributes.SequentialLayout je nastavena. Hodnoty TypeAttributes.AutoLayoutvýčtu , TypeAttributes.ExplicitLayouta TypeAttributes.SequentialLayout označují způsob, jakým jsou pole typu rozložena v paměti.

U dynamických typů můžete zadat TypeAttributes.SequentialLayout při vytváření typu. V kódu použijte StructLayoutAttribute atribut s LayoutKind.Sequential hodnotou výčtu na typ, abyste určili, že rozložení je sekvenční.

Poznámka

Nelze použít metodu GetCustomAttributes k určení, zda StructLayoutAttribute byl použit na typ.

Další informace najdete v části 9.1.2 specifikace dokumentace k Common Language Infrastructure (CLI) Oddíl II: Definice metadat a sémantika.

Pokud aktuální Type představuje konstruovaný obecný typ, tato vlastnost platí pro definici obecného typu, ze které byl typ vytvořen. Pokud například aktuální Type představuje MyGenericType<int> (MyGenericType(Of Integer) v jazyce Visual Basic), je hodnota této vlastnosti určena hodnotou MyGenericType<T>.

Pokud current Type představuje parametr typu v definici obecného typu nebo obecné metody, tato vlastnost vždy vrátí false.

Platí pro

Viz také