Type.IsLayoutSequential プロパティ

定義

現在の型のフィールドが、定義済みまたはメタデータに対して出力された順序で、連続して配置されているかどうかを示す値を取得します。

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

プロパティ値

Boolean

現在の型の true プロパティに Attributes が含まれる場合は SequentialLayout。それ以外の場合は 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.ExplicitLayout 、およびの TypeAttributes.SequentialLayout 各列挙値は、型のフィールドをメモリにレイアウトする方法を示します。

動的な型の場合は、 TypeAttributes.SequentialLayout 型をいつ作成するかを指定できます。 コードで、 StructLayoutAttribute 列挙値を含む属性を LayoutKind.Sequential 型に適用して、レイアウトがシーケンシャルであることを指定します。

注意

メソッドを使用して GetCustomAttributes 、が StructLayoutAttribute 型に適用されているかどうかを判断することはできません。

詳細については、共通言語基盤 (CLI) のドキュメント「パーティション II: メタデータの定義とセマンティクス」の9.1.2 のセクションを参照してください。 ドキュメントはオンラインで入手できます。MSDN の「ECMA C# and Common Language Infrastructure Standards」 (ECMA の C# および共通言語基盤の標準規格) と、ECMA のインターナショナル Web サイトにある「Standard ECMA-335 - Common Language Infrastructure (CLI)」を参照してください。

現在のが Type 構築ジェネリック型を表している場合、このプロパティは、型が構築された元のジェネリック型定義に適用されます。 たとえば、現在のが Type (Visual Basic) を表している場合、 MyGenericType<int> MyGenericType(Of Integer) このプロパティの値はによって決定され MyGenericType<T> ます。

現在のが Type ジェネリック型またはジェネリックメソッドの定義の型パラメーターを表している場合、このプロパティは常にを返し false ます。

適用対象

こちらもご覧ください