Sdílet prostřednictvím


Type.IsAutoLayout Vlastnost

Definice

Získá hodnotu určující, zda pole aktuálního typu jsou rozložena automaticky modulem CLR (Common Language Runtime).

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

Hodnota vlastnosti

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

Implementuje

Příklady

Následující příklad vytvoří instanci typu a zobrazí IsAutoLayout vlastnost.

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

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.AutoLayout je nastavena. Hodnoty TypeAttributes.AutoLayoutvýčtu označujíTypeAttributes.ExplicitLayout způsob, TypeAttributes.SequentialLayout jakým jsou pole typu rozložena v paměti.

U dynamických typů můžete určit TypeAttributes.AutoLayout , kdy typ vytvoříte. V kódu použijte StructLayoutAttribute atribut s hodnotou výčtu LayoutKind.Auto na typ, aby modul runtime určil vhodný způsob rozložení třídy.

Poznámka:

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

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é