다음을 통해 공유


Type.IsLayoutSequential 속성

정의

현재 형식의 필드가 정의되거나 메타데이터로 내보내는 순서대로 순차적으로 배치되는지 여부를 나타내는 값을 가져옵니다.

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

속성 값

true 현재 형식의 속성에 Attributes ;가 포함되어 SequentialLayout있으면 이고, false그렇지 않으면 .

구현

예제

다음 예제에서는 클래스의 열거형 값이 설정된 클래스 LayoutKind.Sequential 의 인스턴스를 StructLayoutAttribute 만들고, 속성을 확인하고 IsLayoutSequential , 결과를 표시합니다.

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

설명

이 속성은 편의를 위해 제공됩니다. 또는 열거형 값을 사용하여 TypeAttributes.LayoutMask 형식 레이아웃 특성을 선택한 다음 설정 여부를 TypeAttributes.SequentialLayout 테스트할 수 있습니다. , TypeAttributes.ExplicitLayoutTypeAttributes.SequentialLayout 열거형 값은 TypeAttributes.AutoLayout형식의 필드가 메모리에 배치되는 방식을 나타냅니다.

동적 형식의 경우 형식을 만들 때 지정할 TypeAttributes.SequentialLayout 수 있습니다. 코드에서 열거형 값이 있는 LayoutKind.Sequential 특성을 형식에 적용 StructLayoutAttribute 하여 레이아웃이 순차적임을 지정합니다.

메모

메서드를 사용하여 형식에 GetCustomAttributes 적용되었는지 여부를 StructLayoutAttribute 확인할 수 없습니다.

자세한 내용은 CLI(공용 언어 인프라) 설명서 "Partition II: 메타데이터 정의 및 의미 체계"에 대한 사양의 섹션 9.1.2를 참조하세요.

현재 Type 생성 된 제네릭 형식을 나타내는 경우이 속성은 형식이 생성 된 제네릭 형식 정의에 적용 됩니다. 예를 들어 현재 Type 가 (Visual Basic에서)MyGenericType(Of Integer) 나타내는 MyGenericType<int> 경우 이 속성의 값은 .에 의해 MyGenericType<T>결정됩니다.

현재 Type 제네릭 형식 또는 제네릭 메서드의 정의에서 형식 매개 변수를 나타내는 경우 이 속성은 항상 반환됩니다 false.

적용 대상

추가 정보