Type.IsAutoLayout 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取指示当前类型的字段是否由公共语言运行时自动放置的值。
public:
 property bool IsAutoLayout { bool get(); };public bool IsAutoLayout { get; }member this.IsAutoLayout : boolPublic ReadOnly Property IsAutoLayout As 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);
    }
}
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
注解
为了方便起见,提供此属性。 或者,可以使用 TypeAttributes.LayoutMask 枚举值来选择类型布局属性,然后测试是否 TypeAttributes.AutoLayout 设置了 。 TypeAttributes.AutoLayout、TypeAttributes.ExplicitLayout 和 TypeAttributes.SequentialLayout 枚举值指示类型字段在内存中的布局方式。
对于动态类型,可以在创建类型时指定 TypeAttributes.AutoLayout 。 在代码中,将 StructLayoutAttribute 具有 LayoutKind.Auto 枚举值的特性应用于类型,以便运行时确定布局类的适当方式。
注意
不能使用 GetCustomAttributes 方法确定是否 StructLayoutAttribute 已将 应用于类型。
如果当前 Type 表示构造的泛型类型,则此属性适用于从中构造该类型的泛型类型定义。 例如,如果当前 Type 表示 MyGenericType<int> Visual Basic) 中的 (MyGenericType(Of Integer) ,则此属性的值由 MyGenericType<T>.
如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false。