Type.IsAutoLayout Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar ett värde som anger om fälten av den aktuella typen anges automatiskt av den gemensamma språkkörningen.
public:
property bool IsAutoLayout { bool get(); };
public bool IsAutoLayout { get; }
member this.IsAutoLayout : bool
Public ReadOnly Property IsAutoLayout As Boolean
Egenskapsvärde
true om egenskapen Attributes för den aktuella typen innehåller AutoLayout, annars , false.
Implementeringar
Exempel
I följande exempel skapas en instans av typen och egenskapen IsAutoLayout visas.
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
Kommentarer
Den här egenskapen tillhandahålls som en bekvämlighet. Du kan också använda TypeAttributes.LayoutMask uppräkningsvärdet för att välja typlayoutattributen och sedan testa om TypeAttributes.AutoLayout har angetts. Värdena TypeAttributes.AutoLayout,TypeAttributes.ExplicitLayoutoch TypeAttributes.SequentialLayout uppräkning anger hur fälten i typen anges i minnet.
För dynamiska typer kan du ange TypeAttributes.AutoLayout när du skapar typen. I kod använder du StructLayoutAttribute attributet med LayoutKind.Auto uppräkningsvärdet för typen för att låta körningen bestämma det lämpliga sättet att lägga ut klassen.
Note
Du kan inte använda GetCustomAttributes metoden för att avgöra om har StructLayoutAttribute tillämpats på en typ.
Om strömmen Type representerar en konstruerad allmän typ gäller den här egenskapen för den generiska typdefinition som typen skapades från. Om den aktuella Type till exempel representerar MyGenericType<int> (MyGenericType(Of Integer) i Visual Basic) bestäms värdet för den här egenskapen av MyGenericType<T>.
Om strömmen Type representerar en typparameter i definitionen av en allmän typ eller allmän metod returnerar falseden här egenskapen alltid .