Type.IsAutoLayout 属性
获取一个指示是否为 Type 选择了类布局属性 (Attribute) AutoLayout 的值。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsAutoLayout As Boolean
用法
Dim instance As Type
Dim value As Boolean
value = instance.IsAutoLayout
public bool IsAutoLayout { get; }
public:
virtual property bool IsAutoLayout {
bool get () sealed;
}
/** @property */
public final boolean get_IsAutoLayout ()
public final function get IsAutoLayout () : boolean
属性值
如果为 Type 选定了类布局属性 (Attribute) AutoLayout,则为 true;否则为 false。
备注
LayoutMask 用于选择类布局属性。类布局属性 (Attribute)(AutoLayout、SequentialLayout 和 ExplicitLayout)定义类实例的字段在内存中进行布局的方式。
使用 AutoLayout 属性 (Attribute) 让运行时引擎决定对类的对象进行布局的最佳方式。用 AutoLayout 属性 (Attribute) 标记的类指示加载程序将选择适当的方式对类进行布局;任何可能已被指定的布局信息均被忽略。
如果当前 Type 表示某种已构造的泛型类型,则此属性适用于从中构造此类型的泛型类型定义。例如,如果当前 Type 表示 MyGenericType<int>
(在 Visual Basic 中为 MyGenericType(Of Integer)
),则此属性的值由 MyGenericType<T>.
确定。
如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false。
示例
下面的示例创建类型的实例,并显示 IsAutoLayout 属性 (Property)。
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic
' The Demo class is has the AutoLayout attribute.
<StructLayoutAttribute(LayoutKind.Auto)> _
Public Class Demo
End Class
Public Class Example
Public Shared Sub Main()
' Get the Type object for the Demo class.
Dim myType As Type = GetType(Demo)
' Get and display the IsAutoLayout property of the
' Demo class.
Console.WriteLine("The AutoLayout property for the Demo class is '{0}'.", _
myType.IsAutoLayout.ToString())
End Sub
End Class
using System;
using System.Runtime.InteropServices;
// The Demo class is attributed as AutoLayout.
[StructLayoutAttribute(LayoutKind.Auto)]
public class Demo
{
}
public class Example
{
public static void Main()
{
// Create an instance of the Type class using the GetType method.
Type myType=typeof(Demo);
// Get and display the IsAutoLayout property of the
// Demoinstance.
Console.WriteLine("\nThe AutoLayout property for the Demo class is {0}.",
myType.IsAutoLayout);
}
}
#using <System.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;
// The MyDemoAttribute class is selected as AutoLayout.
[StructLayoutAttribute(LayoutKind::Auto)]
public ref class MyDemoAttribute{};
void MyAutoLayoutMethod( String^ typeName )
{
try
{
// Create an instance of the Type class using the GetType method.
Type^ myType = Type::GetType( typeName );
// Get and display the IsAutoLayout property of the
// MyDemoAttribute instance.
Console::WriteLine( "\nThe AutoLayout property for the MyDemoAttribute is {0}.", myType->IsAutoLayout );
}
catch ( Exception^ e )
{
Console::WriteLine( "\nAn exception occurred: {0}.", e->Message );
}
}
int main()
{
MyAutoLayoutMethod( "MyDemoAttribute" );
}
import System.*;
import System.Reflection.*;
import System.ComponentModel.*;
import System.Runtime.InteropServices.*;
// The MyDemoAttribute class is selected as AutoLayout.
/** @attribute StructLayoutAttribute(LayoutKind.Auto)
*/
public class MyDemoAttribute
{
} //MyDemoAttribute
public class MyTypeClass
{
public static void main(String[] args)
{
MyAutoLayoutMethod("MyDemoAttribute");
} //main
public static void MyAutoLayoutMethod(String typeName)
{
try {
// Create an instance of the Type class using the GetType method.
Type myType = Type.GetType(typeName);
// Get and display the IsAutoLayout property of the
// MyDemoAttribute instance.
Console.WriteLine("\nThe AutoLayout property for the"
+ " MyDemoAttribute is {0}.", System.Convert.ToString(myType.
get_IsAutoLayout()));
}
catch (System.Exception e) {
Console.WriteLine("\nAn exception occurred: {0}.", e.get_Message());
}
} //MyAutoLayoutMethod
} //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
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
Type 类
Type 成员
System 命名空间
TypeAttributes
IsLayoutSequential
IsExplicitLayout