Type.IsAutoLayout Vlastnost

Definice

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

trueAttributes pokud vlastnost aktuálního typu zahrnuje AutoLayout, jinak hodnota false.

Implementuje

Příklady

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

#using <System.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;

// The MyDemoAttribute class is selected as AutoLayout.

[StructLayoutAttribute(LayoutKind::Auto)]
public ref class MyDemoAttribute{};

void MyAutoLayoutMethod( String^ typeName )
{
   try
   {
      
      // Create an instance of the Type class using the GetType method.
      Type^ myType = Type::GetType( typeName );
      
      // Get and display the IsAutoLayout property of the
      // MyDemoAttribute instance.
      Console::WriteLine( "\nThe AutoLayout property for the MyDemoAttribute is {0}.", myType->IsAutoLayout );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nAn exception occurred: {0}.", e->Message );
   }

}

int main()
{
   MyAutoLayoutMethod( "MyDemoAttribute" );
}
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 k dispozici pro pohodlí. Alternativně můžete použít hodnotu výčtu TypeAttributes.LayoutMask k výběru atributů rozložení typu a poté otestovat, zda TypeAttributes.AutoLayout je nastavena. Hodnoty TypeAttributes.AutoLayoutvýčtu ,TypeAttributes.ExplicitLayout a TypeAttributes.SequentialLayout označují způsob, jakým jsou pole typu rozložena v paměti.

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

Poznámka

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

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

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

Platí pro

Viz také