共用方式為


Type.IsLayoutSequential 屬性

定義

取得表示目前類型的欄位是否已依為其定義或發出至中繼資料之順序,循序配置版面的值。

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

屬性值

Boolean

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

實作

範例

下列範例會建立類別的實例,其已 LayoutKind.Sequential 設定類別中的列舉值 StructLayoutAttribute 、檢查 IsLayoutSequential 屬性,並顯示結果。

#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.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

備註

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

若為動態類型,您可以在 TypeAttributes.SequentialLayout 建立類型時指定。 在程式碼中,將 StructLayoutAttribute 具有列舉值的屬性套用 LayoutKind.Sequential 至類型,以指定該配置為連續。

注意

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

如需詳細資訊,請參閱 (CLI 的通用語言基礎結構規格的章節 9.1.2) 檔「資料分割 II:元資料定義和語義」。 您可以線上取得這份文件;請參閱 MSDN 上的 ECMA C# 和通用語言基礎結構標準,以及 Ecma International 網站上的標準 ECMA-335 - 通用語言基礎結構 (CLI)

如果目前的 Type 代表結構化泛型型別,這個屬性會套用至用來建立型別的泛型型別定義。 例如,如果目前的 Type (代表 MyGenericType<int> MyGenericType(Of Integer) Visual Basic) 中的,則這個屬性的值是由決定 MyGenericType<T>

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

適用於

另請參閱