Type.IsLayoutSequential Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri az értéket, amely jelzi, hogy az aktuális típusú mezők egymás után vannak-e elrendezve a metaadatok definiálásának vagy kiadásának sorrendjében.
public:
property bool IsLayoutSequential { bool get(); };
public bool IsLayoutSequential { get; }
member this.IsLayoutSequential : bool
Public ReadOnly Property IsLayoutSequential As Boolean
Tulajdonság értéke
trueha az Attributes aktuális típus tulajdonsága tartalmazza SequentialLayout; egyébként. false
Megvalósítás
Példák
Az alábbi példa létrehoz egy osztálypéldányt, amelyhez az LayoutKind.Sequential osztály enumerálási értéke StructLayoutAttribute be van állítva, ellenőrzi a IsLayoutSequential tulajdonságot, és megjeleníti az eredményt.
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
class MyTypeSequential1
{
}
[StructLayoutAttribute(LayoutKind.Sequential)]
class MyTypeSequential2
{
public static void Main(string []args)
{
try
{
// Create an instance of myTypeSeq1.
MyTypeSequential1 myObj1 = new MyTypeSequential1();
Type myTypeObj1 = myObj1.GetType();
// Check for and display the SequentialLayout attribute.
Console.WriteLine("\nThe object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential);
// Create an instance of 'myTypeSeq2' class.
MyTypeSequential2 myObj2 = new MyTypeSequential2();
Type myTypeObj2 = myObj2.GetType();
// Check for and display the SequentialLayout attribute.
Console.WriteLine("\nThe object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential);
}
catch(Exception e)
{
Console.WriteLine("\nAn exception occurred: {0}", e.Message);
}
}
}
open System.Runtime.InteropServices
type MyTypeSequential1 = struct end
[<StructLayoutAttribute(LayoutKind.Sequential)>]
type MyTypeSequential2 = struct end
try
// Create an instance of myTypeSeq1.
let myObj1 = MyTypeSequential1()
let myTypeObj1 = myObj1.GetType()
// Check for and display the SequentialLayout attribute.
printfn $"\nThe object myObj1 has IsLayoutSequential: {myTypeObj1.IsLayoutSequential}."
// Create an instance of 'myTypeSeq2' class.
let myObj2 = MyTypeSequential2()
let myTypeObj2 = myObj2.GetType()
// Check for and display the SequentialLayout attribute.
printfn $"\nThe object myObj2 has IsLayoutSequential: {myTypeObj2.IsLayoutSequential}."
with e ->
printfn $"\nAn exception occurred: {e.Message}"
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Class MyTypeSequential1
End Class
<StructLayoutAttribute(LayoutKind.Sequential)> Class MyTypeSequential2
Public Shared Sub Main()
Try
' Create an instance of MyTypeSequential1.
Dim myObj1 As New MyTypeSequential1()
Dim myTypeObj1 As Type = myObj1.GetType()
' Check for and display the SequentialLayout attribute.
Console.WriteLine(ControlChars.Cr + "The object myObj1 has IsLayoutSequential: {0}.", myObj1.GetType().IsLayoutSequential.ToString())
' Create an instance of MyTypeSequential2.
Dim myObj2 As New MyTypeSequential2()
Dim myTypeObj2 As Type = myObj2.GetType()
' Check for and display the SequentialLayout attribute.
Console.WriteLine(ControlChars.Cr + "The object myObj2 has IsLayoutSequential: {0}.", myObj2.GetType().IsLayoutSequential.ToString())
Catch e As Exception
Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
End Try
End Sub
End Class
Megjegyzések
Ez a tulajdonság kényelmesen elérhető. Másik lehetőségként az TypeAttributes.LayoutMask enumerálási érték használatával kiválaszthatja a típuselrendezési attribútumokat, majd ellenőrizheti, hogy be van-e TypeAttributes.SequentialLayout állítva. A TypeAttributes.AutoLayout, TypeAttributes.ExplicitLayoutés TypeAttributes.SequentialLayout enumerálási értékek azt jelzik, hogy a típus mezői hogyan vannak elhelyezve a memóriában.
Dinamikus típusok esetén megadhatja TypeAttributes.SequentialLayout , hogy mikor hozza létre a típust. A kódban alkalmazza az StructLayoutAttributeLayoutKind.Sequential enumerálási értékkel rendelkező attribútumot a típusra, és adja meg, hogy az elrendezés szekvenciális.
Note
A metódus nem használható annak GetCustomAttributes megállapítására, hogy a StructLayoutAttribute rendszer alkalmazva lett-e egy típusra.
További információt a Common Language Infrastructure (CLI) dokumentációjának 9.1.2. szakaszában talál: "Partition II: Metadata Definition and Semantics".
Ha az áram Type egy létrehozott általános típust jelöl, ez a tulajdonság arra az általános típusdefinícióra vonatkozik, amelyből a típust létrehozták. Ha például az aktuális TypeMyGenericType<int> (MyGenericType(Of Integer) Visual Basic), akkor a tulajdonság értékét a MyGenericType<T> határozza meg.
Ha az aktuális Type érték egy típusparamétert jelöl egy általános vagy általános metódus definíciójában, ez a tulajdonság mindig ad vissza false.