Type.IsExplicitLayout 属性

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

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

语法

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

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

属性值

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

备注

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

ExplicitLayout 属性 (Attribute) 标记的类导致加载程序忽略字段序列和使用所提供的显式布局规则,采用的形式为字段偏移量、全部类大小和对齐,或者所有这些形式。

使用 ExplicitLayout 属性指定偏移量(每个字段以此偏移量开始),或者指定全部大小,还可以指定类的对象封装大小。封装大小是各字段之间的空白内存空间,必须为 1、2、4、8 或 16 字节。

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

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

示例

下面的示例创建指定的类型的实例,并显示 MyDemoAttribute 类的 IsExplicitLayout 属性 (Property)。

Imports System
Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic

'The class to be tested for the ExplicitLayout property.
<StructLayoutAttribute(LayoutKind.Explicit)> _
Public Class Demo
End Class

Public Class MyTypeClass
    Public Shared Sub Main()
        'Create an instance of the type using the GetType method.
        Dim myType As Type = GetType(Demo)
        ' Get and display the IsExplicitLayout property.
        Console.WriteLine(vbCrLf & "The IsExplicitLayout property of the Demo type is {0}.", _
            myType.IsExplicitLayout)
    End Sub
End Class
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.InteropServices;
//The class to be tested for the ExplicitLayout property.
[StructLayoutAttribute(LayoutKind.Explicit)]
public class Demo
{
}
public class MyTypeClass
{
    public static void Main(string[] args)
    {
        // Create an instance of the type using the GetType method.
        Type  myType = typeof(Demo);
        // Get and display the IsExplicitLayout property.
        Console.WriteLine("\nThe IsExplicitLayout property of the Demo type is {0}.", 
            myType.IsExplicitLayout); 
    }
}
#using <System.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;

//The class to be tested for the ExplicitLayout property.

[StructLayoutAttribute(LayoutKind::Explicit)]
public ref class MyDemoAttribute{};

void MyIsExplicitLayoutMethod( String^ typeName )
{
   try
   {
      
      // Create an instance of the type using the GetType method.
      Type^ myType = Type::GetType( typeName );
      
      // Get and display the IsExplicitLayout property.
      Console::WriteLine( "\nThe IsExplicitLayout property of the MyDemoAttribute instance is {0}.", myType->IsExplicitLayout );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nAn exception occurred: {0}.", e->Message );
   }

}

int main()
{
   MyIsExplicitLayoutMethod( "MyDemoAttribute" );
}
import System.*;
import System.Reflection.*;
import System.ComponentModel.*;
import System.Runtime.InteropServices.*;

//The class to be tested for the ExplicitLayout property.
/** @attribute StructLayoutAttribute(LayoutKind.Explicit)
 */
public class MyDemoAttribute
{
} //MyDemoAttribute

public class MyTypeClass
{
    public static void main(String[] args)
    {
        MyIsExplicitLayoutMethod("MyDemoAttribute");
    } //main

    public static void MyIsExplicitLayoutMethod(String typeName)
    {
        try {
            // Create an instance of the type using the GetType method.
            Type myType = Type.GetType(typeName);
            // Get and display the IsExplicitLayout property.
            Console.WriteLine("\nThe IsExplicitLayout property of the " 
                + "MyDemoAttribute instance is {0}.", System.Convert.
                ToString(myType.get_IsExplicitLayout()));
        }
        catch (System.Exception e) {
            Console.WriteLine("\nAn exception occurred: {0}.", e.get_Message());
        }
    } //MyIsExplicitLayoutMethod
} //MyTypeClass

平台

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 属性
IsLayoutSequential

其他资源

元数据概述