Type.IsLayoutSequential 属性

获取一个值,通过该值指示是否为 Type 选定了类布局属性 (Attribute) SequentialLayout

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public ReadOnly Property IsLayoutSequential As Boolean
用法
Dim instance As Type
Dim value As Boolean

value = instance.IsLayoutSequential
public bool IsLayoutSequential { get; }
public:
virtual property bool IsLayoutSequential {
    bool get () sealed;
}
/** @property */
public final boolean get_IsLayoutSequential ()
public final function get IsLayoutSequential () : boolean

属性值

如果为 Type 选定了类布局属性 (Attribute) SequentialLayout,则为 true;否则为 false

备注

LayoutMask 用于选择类布局属性。类布局属性 (Attribute)(AutoLayoutSequentialLayoutExplicitLayout)定义类实例的字段在内存中进行布局的方式。

有关更多信息,请参见 Common Language Infrastructure (CLI) 规范文档的第 9.1.2 节“Partition II: Metadata Definition and Semantics”(第二部分:元数据定义和语义)。该文档可从下面的网站上联机获得:https://msdn.microsoft.com/net/ecma/http://www.ecma-international.org/publications/standards/Ecma-335.htm

如果当前 Type 表示某种已构造的泛型类型,则此属性适用于从中构造此类型的泛型类型定义。例如,如果当前 Type 表示 MyGenericType<int> (在 Visual Basic 中为 MyGenericType(Of Integer)),则此属性 (Property) 的值由 MyGenericType<T> 确定。

如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false

示例

下面的示例创建一个类的实例(已为该类在 StructLayoutAttribute 类中设置了 LayoutKind 枚举的 Sequential 成员),检查属性 (Property) IsLayoutSequential,然后显示结果。

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
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);
        }
    }
}
#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 );
   }

}
import System.*;
import System.Reflection.*;
import System.ComponentModel.*;
import System.Runtime.InteropServices.*;
class MyTypeSequential1
{
} //MyTypeSequential1

/** @attribute 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}.",
                System.Convert.ToString(myObj1.GetType().
                get_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}.",
                System.Convert.ToString(myObj2.GetType().
                get_IsLayoutSequential()));
        }
        catch (System.Exception e) {
            Console.WriteLine("\nAn exception occurred: {0}", e.get_Message());
        }
    } //main
} //MyTypeSequential2

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Type 类
Type 成员
System 命名空间
TypeAttributes
Type.IsAutoLayout 属性
Type.IsExplicitLayout 属性

其他资源

元数据概述