Type.IsLayoutSequential Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une valeur indiquant si les champs du type actuel sont disposés séquentiellement, dans l’ordre dans lequel ils ont été définis ou émis dans les métadonnées.
public:
property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean
Valeur de propriété
true si la Attributes propriété du type actuel inclut SequentialLayout; sinon, false.
Implémente
Exemples
L’exemple suivant crée une instance d’une classe pour laquelle la LayoutKind.Sequential valeur d’énumération de la StructLayoutAttribute classe a été définie, recherche la IsLayoutSequential propriété et affiche le résultat.
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
Remarques
Cette propriété est fournie comme commodité. Vous pouvez également utiliser la TypeAttributes.LayoutMask valeur d’énumération pour sélectionner les attributs de disposition de type, puis tester si TypeAttributes.SequentialLayout elle est définie. Les TypeAttributes.AutoLayoutvaleurs , TypeAttributes.ExplicitLayoutet TypeAttributes.SequentialLayout d’énumération indiquent la façon dont les champs du type sont disposés en mémoire.
Pour les types dynamiques, vous pouvez spécifier quand vous créez TypeAttributes.SequentialLayout le type. Dans le code, appliquez l’attribut StructLayoutAttribute avec la LayoutKind.Sequential valeur d’énumération au type pour spécifier que la disposition est séquentielle.
Note
Vous ne pouvez pas utiliser la GetCustomAttributes méthode pour déterminer si celle-ci StructLayoutAttribute a été appliquée à un type.
Pour plus d’informations, consultez la section 9.1.2 de la spécification de la documentation de Common Language Infrastructure (CLI), « Partition II : Définition et sémantique des métadonnées ».
Si le courant Type représente un type générique construit, cette propriété s’applique à la définition de type générique à partir de laquelle le type a été construit. Par exemple, si la valeur actuelle Type représente MyGenericType<int> (MyGenericType(Of Integer) en Visual Basic), la valeur de cette propriété est déterminée par MyGenericType<T>.
Si le paramètre actuel Type représente un paramètre de type dans la définition d’un type générique ou d’une méthode générique, cette propriété retourne falsetoujours .