Sdílet prostřednictvím


Type.IsLayoutSequential Vlastnost

Definice

Získá hodnotu určující, zda pole aktuálního typu jsou rozložena 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

true Attributes pokud vlastnost aktuálního typu zahrnuje SequentialLayout; jinak , false.

Implementuje

Příklady

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

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 poskytována jako pohodlí. Případně můžete použít hodnotu výčtu TypeAttributes.LayoutMask k výběru atributů rozložení typu a pak otestovat, zda TypeAttributes.SequentialLayout je nastavena. Hodnoty TypeAttributes.AutoLayout, TypeAttributes.ExplicitLayouta TypeAttributes.SequentialLayout výčtu označují způsob, jakým jsou pole typu rozložena v paměti.

U dynamických typů můžete určit TypeAttributes.SequentialLayout , kdy typ vytvoříte. V kódu použijte StructLayoutAttribute atribut s hodnotou výčtu LayoutKind.Sequential na typ, aby bylo možné určit, že rozložení je sekvenční.

Poznámka:

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

Další informace najdete v části 9.1.2 specifikace pro dokumentaci k common language infrastructure (CLI), oddíl II: Definice metadat a sémantika.

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

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

Platí pro

Viz také