Condividi tramite


Type.IsLayoutSequential Proprietà

Definizione

Ottiene un valore che indica se i campi del tipo corrente sono disposti in sequenza, nell'ordine in cui sono stati definiti o emessi nei metadati.

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

Valore della proprietà

true se la Attributes proprietà del tipo corrente include SequentialLayout; in caso contrario, false.

Implementazioni

Esempio

Nell'esempio seguente viene creata un'istanza di una classe per la quale è stato impostato il LayoutKind.Sequential valore di enumerazione nella StructLayoutAttribute classe , viene verificata la IsLayoutSequential proprietà e viene visualizzato il risultato.

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

Commenti

Questa proprietà viene fornita per praticità. In alternativa, è possibile usare il TypeAttributes.LayoutMask valore di enumerazione per selezionare gli attributi di layout del tipo e quindi verificare se TypeAttributes.SequentialLayout è impostato. I TypeAttributes.AutoLayoutvalori di enumerazione , TypeAttributes.ExplicitLayoute TypeAttributes.SequentialLayout indicano la modalità di disposizione dei campi del tipo in memoria.

Per i tipi dinamici, è possibile specificare TypeAttributes.SequentialLayout quando si crea il tipo. Nel codice applicare l'attributo StructLayoutAttribute con il LayoutKind.Sequential valore di enumerazione al tipo per specificare che il layout è sequenziale.

Annotazioni

Non è possibile utilizzare il GetCustomAttributes metodo per determinare se l'oggetto StructLayoutAttribute è stato applicato a un tipo.

Per altre informazioni, vedere la sezione 9.1.2 della specifica per la documentazione di Common Language Infrastructure (CLI), "Partition II: Metadata Definition and Semantics".

Se l'oggetto corrente Type rappresenta un tipo generico costruito, questa proprietà si applica alla definizione di tipo generico da cui è stato costruito il tipo. Ad esempio, se l'oggetto corrente Type rappresenta MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic), il valore di questa proprietà viene determinato da MyGenericType<T>.

Se l'oggetto corrente Type rappresenta un parametro di tipo nella definizione di un tipo generico o di un metodo generico, questa proprietà restituisce falsesempre .

Si applica a

Vedi anche