Type.IsAutoLayout 屬性

定義

取得表示目前類型的欄位是否已由 Common Language Runtime 自動配置版面的值。

C#
public bool IsAutoLayout { get; }

屬性值

如果目前類型的 Attributes 屬性包含 AutoLayout則為 true,否則為 false

實作

範例

下列範例會建立 類型的實例,並顯示 IsAutoLayout 屬性。

C#
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);
    }
}

備註

這個屬性會以方便的方式提供。 或者,您可以使用 TypeAttributes.LayoutMask 列舉值來選取類型配置屬性,然後測試是否已 TypeAttributes.AutoLayout 設定。 、 TypeAttributes.AutoLayoutTypeAttributes.ExplicitLayoutTypeAttributes.SequentialLayout 列舉值表示在記憶體中配置類型欄位的方式。

針對動態類型,您可以在建立類型時指定 TypeAttributes.AutoLayout 。 在程式碼中,將 StructLayoutAttribute 具有 LayoutKind.Auto 列舉值的 屬性套用至型別,讓執行時間判斷配置類別的適當方式。

備註

您無法使用 GetCustomAttributes 方法來判斷 是否已 StructLayoutAttribute 套用至型別。

如果目前的 Type 表示已建構的泛型型別,則此屬性會套用至建構型別的來源泛型型別定義。 例如,如果目前的 Type 代表 MyGenericType<int> Visual Basic) 中的 (MyGenericType(Of Integer) ,則此屬性的值是由 MyGenericType<T>.

如果目前的 Type 代表泛型型別或泛型方法定義中的型別參數,這個屬性一律會傳 false 回 。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另請參閱