Type.IsAutoLayout 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 automatiquement par le Common Language Runtime.
public:
property bool IsAutoLayout { bool get(); };
public bool IsAutoLayout { get; }
member this.IsAutoLayout : bool
Public ReadOnly Property IsAutoLayout As Boolean
Valeur de propriété
true si la Attributes propriété du type actuel inclut AutoLayout; sinon, false.
Implémente
Exemples
L’exemple suivant crée une instance du type et affiche la IsAutoLayout propriété.
using System;
using System.Runtime.InteropServices;
// The Demo class is attributed as AutoLayout.
[StructLayoutAttribute(LayoutKind.Auto)]
public class Demo
{
}
public class Example
{
public static void Main()
{
// Create an instance of the Type class using the GetType method.
Type myType=typeof(Demo);
// Get and display the IsAutoLayout property of the
// Demoinstance.
Console.WriteLine("\nThe AutoLayout property for the Demo class is {0}.",
myType.IsAutoLayout);
}
}
open System.Runtime.InteropServices
// The Demo class is attributed as AutoLayout.
[<StructLayoutAttribute(LayoutKind.Auto)>]
type Demo = class end
// Create an instance of the Type class using the GetType method.
let myType = typeof<Demo>
// Get and display the IsAutoLayout property of the
// Demoinstance.
printfn $"\nThe AutoLayout property for the Demo class is {myType.IsAutoLayout}."
Imports System.Runtime.InteropServices
' The Demo class is has the AutoLayout attribute.
<StructLayoutAttribute(LayoutKind.Auto)> _
Public Class Demo
End Class
Public Class Example
Public Shared Sub Main()
' Get the Type object for the Demo class.
Dim myType As Type = GetType(Demo)
' Get and display the IsAutoLayout property of the
' Demo class.
Console.WriteLine("The AutoLayout property for the Demo class is '{0}'.", _
myType.IsAutoLayout.ToString())
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.AutoLayout 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.AutoLayout le type. Dans le code, appliquez l’attribut StructLayoutAttribute avec la LayoutKind.Auto valeur d’énumération au type pour permettre au runtime de déterminer la façon appropriée de définir la classe.
Note
Vous ne pouvez pas utiliser la GetCustomAttributes méthode pour déterminer si celle-ci StructLayoutAttribute a été appliquée à un type.
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 .