Visual Basic 中使用的属性

更新:2007 年 11 月

下表列出 Visual Basic 中使用的一些较通用的属性。有关特定属性的信息,请在“帮助”系统的“索引”或“搜索”框中键入属性名。

属性

用途

ComClassAttribute 类

指示编译器该类应该作为 COM 对象公开。特定于 Visual Basic。

HideModuleNameAttribute 类

允许只使用模块需要的限定访问模块成员。

VBFixedStringAttribute 类

指定随文件输入和输出函数一起使用的结构中固定长度字符串的大小。特定于 Visual Basic。

VBFixedArrayAttribute 类

指定随文件输入和输出函数一起使用的结构中固定数组的大小。特定于 Visual Basic。

WebMethodAttribute

使用 SOAP 协议使方法可调用。用于 XML Web services 中。

SerializableAttribute

指示类可以被序列化。

MarshalAsAttribute

确定应如何在 Visual Basic 的托管代码和像 Windows API 这样的非托管代码之间封送参数。由公共语言运行库使用。

AttributeUsageAttribute

指定如何使用属性。

DllImportAttribute

指示将属性化方法作为从非托管 DLL 中的导出来实现。

特定于 Visual Basic 的属性

以下三个属性特定于 Visual Basic:COMClassAttribute、VBFixedStringAttribute 和 VBFixedArray。

COMClassAttribute

使用 COMClassAttribute 可简化从 Visual Basic 创建 COM 组件的过程。COM 对象与 .NET Framework 程序集差别很大,如果没有 COMClassAttribute,则从 Visual Basic 生成 COM 对象需要经过很多步骤。对于标记为 COMClassAttribute 的类,编译器会自动执行这些步骤中的许多步骤。

HideModuleNameAttribute

使用 HideModuleNameAttribute 可以允许只使用模块需要的限定访问模块成员。

VBFixedStringAttribute

使用 VBFixedStringAttribute 可强制 Visual Basic 创建定长字符串。字符串的长度在默认情况下是可变的,此属性在将字符串存储到文件时很有用。以下代码对此进行了说明:

Structure Worker
    ' The runtime uses VBFixedString to determine 
    ' if the field should be written out as a fixed size.
    <VBFixedString(10)> Public LastName As String
    <VBFixedString(7)> Public Title As String
    <VBFixedString(2)> Public Rank As String
End Structure

VBFixedArrayAttribute

使用 VBFixedArrayAttribute 可声明固定大小的数组。像 Visual Basic 字符串一样,数组的长度在默认情况下是可变的。此属性在序列化数据或将数据写入文件时很有用。

请参见

概念

Visual Basic 中的全局属性

应用属性

检索存储在属性中的信息

编写自定义属性

参考

ComClassAttribute 类

VBFixedArrayAttribute 类

VBFixedStringAttribute 类

System.Runtime.InteropServices

其他资源

利用属性扩展元数据