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.

 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{};

ref class MyTypeSequential2{};

int main()
      // 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
class MyTypeSequential2
    public static void Main(string []args)
            // 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()
            ' 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.

有关详细信息,请参阅部分 9.1.2 有关公共语言基础结构 (CLI) 文档规范的"第二部分:元数据定义和语义"。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.