Freigeben über


Type.IsAutoLayout-Eigenschaft

Ruft einen Wert ab, der angibt, ob für Type das Klassenlayoutattribut AutoLayout ausgewählt ist.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property IsAutoLayout As Boolean
'Usage
Dim instance As Type
Dim value As Boolean

value = instance.IsAutoLayout
public bool IsAutoLayout { get; }
public:
virtual property bool IsAutoLayout {
    bool get () sealed;
}
/** @property */
public final boolean get_IsAutoLayout ()
public final function get IsAutoLayout () : boolean

Eigenschaftenwert

true, wenn für Type das Klassenlayoutattribut AutoLayout ausgewählt ist, andernfalls false.

Hinweise

Die Klassenlayoutattribute werden mit LayoutMask ausgewählt. Die Klassenlayoutattribute (AutoLayout, SequentialLayout und ExplicitLayout) definieren das Layout der Felder der Klasseninstanz im Speicher.

Verwenden Sie das AutoLayout-Attribut, um das bestmögliche Layout der Objekte der Klasse durch das Laufzeitmodul bestimmen zu lassen. Mit dem AutoLayout-Attribut markierte Klassen zeigen an, dass das Ladeprogramm ein angemessenes Klassenlayout auswählt. Eventuell angegebene Layoutinformationen werden nicht beachtet.

Wenn der aktuelle Type einen konstruierten generischen Typ darstellt, gilt diese Eigenschaft für die generische Typdefinition, aus der der Typ konstruiert wurde. Wenn z. B. der aktuelle TypeMyGenericType<int> (MyGenericType(Of Integer) in Visual Basic) darstellt, wird der Wert dieser Eigenschaft durch MyGenericType<T>. bestimmt.

Wenn der aktuelle Type einen Typparameter in der Definition eines generischen Typs oder einer generischen Methoden darstellt, gibt diese Eigenschaft immer false zurück.

Beispiel

Im folgenden Beispiel wird eine Instanz des Typs erstellt, und die IsAutoLayout-Eigenschaft wird angezeigt.

Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic

' 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 
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); 
    }
}
#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" );
}
import System.*;
import System.Reflection.*;
import System.ComponentModel.*;
import System.Runtime.InteropServices.*;

// The MyDemoAttribute class is selected as AutoLayout.
/** @attribute StructLayoutAttribute(LayoutKind.Auto)
 */
public class MyDemoAttribute
{
} //MyDemoAttribute

public class MyTypeClass
{
    public static void main(String[] args)
    {
        MyAutoLayoutMethod("MyDemoAttribute");
    } //main

    public static 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}.", System.Convert.ToString(myType.
                get_IsAutoLayout()));
        }
        catch (System.Exception e) {
            Console.WriteLine("\nAn exception occurred: {0}.", e.get_Message());
        }
    } //MyAutoLayoutMethod
} //MyTypeClass

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Type-Klasse
Type-Member
System-Namespace
TypeAttributes
IsLayoutSequential
IsExplicitLayout

Weitere Ressourcen

Metadatenübersicht