Type.IsAutoLayout プロパティ

定義

現在の型のフィールドが、共通言語ランタイムによって自動的に配置されているかどうかを示す値を取得します。

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

プロパティ値

Boolean

現在の型の true プロパティに Attributes が含まれる場合は AutoLayout。それ以外の場合は false

実装

次の例では、 型のインスタンスを作成し、 プロパティを表示 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

注釈

このプロパティは便利な方法で提供されます。 または、列挙値を使用して型レイアウト属性を選択し、 が設定 TypeAttributes.LayoutMask されているかどうかを TypeAttributes.AutoLayout テストすることもできます。 TypeAttributes.AutoLayout、、 TypeAttributes.ExplicitLayout および 列挙 TypeAttributes.SequentialLayout 値は、型のフィールドをメモリに配置する方法を示します。

動的型の場合は、型 TypeAttributes.AutoLayout を作成するときにを指定できます。 コードでは、列挙値を持つ 属性を型に適用して、ランタイムがクラスをレイアウトするための適切な方法 StructLayoutAttribute LayoutKind.Auto を決定します。

注意

メソッドを使用 GetCustomAttributes して、 が型に StructLayoutAttribute 適用されているかどうかを判断することはできません。

現在の が構築されたジェネリック型を表す場合、このプロパティは、型の構築に使用されたジェネリック型 Type の定義に適用されます。 たとえば、現在の が を表す場合 (Visual Basic)、このプロパティの値は によって Type MyGenericType<int> MyGenericType(Of Integer) 決定されます。MyGenericType<T>.

現在の がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表している場合、このプロパティは常に Type を返します false

適用対象

こちらもご覧ください