Type.IsAutoLayout Właściwość

Definicja

Pobiera wartość wskazującą, czy pola bieżącego typu są układane automatycznie przez środowisko uruchomieniowe języka wspólnego.

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

Wartość właściwości

Boolean

true Jeśli właściwość Attributes bieżącego typu zawiera wartość AutoLayout ; w przeciwnym razie wartość false .

Implementuje

Przykłady

Poniższy przykład tworzy wystąpienie typu i wyświetla właściwość 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" );
}
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);
    }
}
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

Uwagi

Ta właściwość jest dostarczana jako udogodnienie. Alternatywnie możesz użyć wartości wyliczenia, aby wybrać atrybuty układu typu, a następnie TypeAttributes.LayoutMask przetestować, TypeAttributes.AutoLayout czy jest ustawiona. Wartości wyliczenia , i wskazują sposób układu pól typu TypeAttributes.AutoLayout TypeAttributes.ExplicitLayout w TypeAttributes.SequentialLayout pamięci.

W przypadku typów dynamicznych można TypeAttributes.AutoLayout określić, kiedy tworzysz typ. W kodzie zastosuj atrybut z wartością wyliczenia do typu, aby pozwolić środowisku uruchomienioweowi określić odpowiedni sposób StructLayoutAttribute LayoutKind.Auto układu klasy.

Uwaga

Nie można użyć GetCustomAttributes metody , aby określić, czy typ został StructLayoutAttribute zastosowany do typu.

Jeśli bieżący reprezentuje skonstruowany typ ogólny, ta właściwość ma zastosowanie do definicji typu ogólnego, z której Type został skonstruowany typ. Jeśli na przykład bieżąca wartość reprezentuje ( w Visual Basic), wartość Type tej właściwości jest MyGenericType<int> MyGenericType(Of Integer) określana przezMyGenericType<T>.

Jeśli bieżący reprezentuje parametr typu w definicji typu ogólnego lub metody Type ogólnej, ta właściwość zawsze zwraca wartość false .

Dotyczy

Zobacz też