Type.IsLayoutSequential Type.IsLayoutSequential Type.IsLayoutSequential Type.IsLayoutSequential Property

定義

取得表示目前類型的欄位是否已依為其定義或發出至中繼資料之順序,循序配置版面的值。Gets a value indicating whether the fields of the current type are laid out sequentially, in the order that they were defined or emitted to the metadata.

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

屬性值

如果目前類型的 true 屬性包含 Attributes 則為 SequentialLayout,否則為 falsetrue if the Attributes property of the current type includes SequentialLayout; otherwise, false.

實作

範例

下列範例會建立類別的執行個體的LayoutKind.Sequential中的列舉值StructLayoutAttribute類別已設定,會檢查IsLayoutSequential屬性,並顯示結果。The following example creates an instance of a class for which the LayoutKind.Sequential enumeration value in the StructLayoutAttribute class has been set, checks for the IsLayoutSequential property, and displays the result.

#using <System.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;
ref class MyTypeSequential1{};


[StructLayoutAttribute(LayoutKind::Sequential)]
ref class MyTypeSequential2{};

int main()
{
   try
   {
      
      // Create an instance of myTypeSeq1.
      MyTypeSequential1^ myObj1 = gcnew MyTypeSequential1;
      
      // 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 = gcnew MyTypeSequential2;
      
      // 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 );
   }

}

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);
        }
    }
}
Imports System
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic
Class MyTypeSequential1
End Class 'MyTypeSequential1
<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 'Main
End Class 'MyTypeSeq2

備註

為了方便起見提供這個屬性。This property is provided as a convenience. 或者,您可以使用TypeAttributes.LayoutMask列舉值,以選取類型版面配置屬性,然後測試是否TypeAttributes.SequentialLayout設定。Alternatively, you can use the TypeAttributes.LayoutMask enumeration value to select the type layout attributes, and then test whether TypeAttributes.SequentialLayout is set. TypeAttributes.AutoLayoutTypeAttributes.ExplicitLayout,和TypeAttributes.SequentialLayout列舉值,表示類型的欄位配置記憶體中的方式。The TypeAttributes.AutoLayout, TypeAttributes.ExplicitLayout, and TypeAttributes.SequentialLayout enumeration values indicate the way the fields of the type are laid out in memory.

動態類型,您可以指定TypeAttributes.SequentialLayout當您建立的類型。For dynamic types, you can specify TypeAttributes.SequentialLayout when you create the type. 在程式碼中,套用StructLayoutAttribute屬性搭配LayoutKind.Sequential的型別,以指定該版面配置是循序的列舉值。In code, apply the StructLayoutAttribute attribute with the LayoutKind.Sequential enumeration value to the type, to specify that layout is sequential.

注意

您無法使用GetCustomAttributes方法,以判斷是否StructLayoutAttribute已套用至型別。You cannot use the GetCustomAttributes method to determine whether the StructLayoutAttribute has been applied to a type.

如需詳細資訊,請參閱 Common Language Infrastructure (CLI) 文件規格的章節 9.1.2"Partition II:中繼資料定義和語意 」。For more information, see section 9.1.2 of the specification for the Common Language Infrastructure (CLI) documentation, "Partition II: Metadata Definition and Semantics". 您可以線上取得這份文件;請參閱 MSDN 上的 ECMA C# 和通用語言基礎結構標準,以及 Ecma International 網站上的標準 ECMA-335 - 通用語言基礎結構 (CLI)The documentation is available online; see ECMA C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.

如果目前Type代表建構泛型型別,這個屬性會套用至泛型型別定義從中建構的類型。If the current Type represents a constructed generic type, this property applies to the generic type definition from which the type was constructed. 例如,如果目前Type代表MyGenericType<int>(MyGenericType(Of Integer)在 Visual Basic 中),這個屬性的值取決於MyGenericType<T>For example, if the current Type represents MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic), the value of this property is determined by MyGenericType<T>.

如果目前Type表示的類型參數的泛型類型或泛型方法定義中這個屬性一律傳回falseIf the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

適用於

另請參閱