WriteOnlyArrayAttribute 类


当应用于 Windows 运行时组件中的数组参数时,指定传递到该参数的数组的内容仅用于输出。When applied to an array parameter in a Windows Runtime component, specifies that the contents of an array that is passed to that parameter are used only for output. 调用方不保证对内容进行了初始化,因此,所调用的方法不应读取内容。The caller does not guarantee that the contents are initialized, and the called method should not read the contents.

public ref class WriteOnlyArrayAttribute sealed : Attribute
public sealed class WriteOnlyArrayAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=false)]
public sealed class WriteOnlyArrayAttribute : Attribute
type WriteOnlyArrayAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=false)>]
type WriteOnlyArrayAttribute = class
    inherit Attribute
Public NotInheritable Class WriteOnlyArrayAttribute
Inherits Attribute


如果组件中的数组参数 Windows 运行时Windows Runtime 是通过 Visual Basic) 中的值 (传递的 ByVal ,则必须向其应用以下属性之一:If an array parameter in your Windows 运行时Windows Runtime component is passed by value (ByVal in Visual Basic), you must apply one of the following attributes to it:

  • 如果要将 ReadOnlyArrayAttribute 数组的内容仅用于输入,则应用该特性。Apply the ReadOnlyArrayAttribute attribute if you intend the contents of the array to be used for input only.

  • 如果要将 WriteOnlyArrayAttribute 数组的内容 (仅用于输出,请应用特性,方法设置数组的内容,但不) 读取这些内容。Apply the WriteOnlyArrayAttribute attribute if you intend the contents of the array to be used for output only (that is, the method sets the contents of the array but does not read them).

将这两个特性应用于一个参数会导致错误。Applying both attributes to a parameter causes an error. 有关详细信息,包括对数组进行更改的标准模式,请参阅在 Windows 开发人员中心将 数组传递到 Windows 运行时组件For more information, including the standard pattern for making changes to an array, see Passing arrays to a Windows Runtime component in the Windows Dev Center.


具有属性的参数的 WriteOnlyArrayAttribute 行为不同,具体取决于调用方是使用本机代码编写还是用托管代码编写的。Parameters that have the WriteOnlyArrayAttribute attribute behave differently depending on whether the caller is written in native code or managed code. 如果调用方是 (JavaScript 或 Visual C++ 组件扩展) 的本机代码,则被调用的方法无法对原始数组的内容进行任何假设。If the caller is native code (JavaScript or Visual C++ component extensions), the called method can't make any assumptions about the contents of the original array. 例如,方法接收的数组可能未初始化,或可能包含默认值。For example, the array the method receives might not be initialized, or might contain default values. 方法应在数组中设置所有元素的值。The method is expected to set the values of all the elements in the array.

如果调用方是托管代码,则调用方的原始数组将传递给被调用方法,就像在 .NET Framework 的任何方法调用中一样。If the caller is managed code, the caller's original array is passed to the called method, as it would be in any method call in the .NET Framework. 数组内容在托管代码中是可变的,因此该方法可以有选择地读取和更改这些值。Array contents are mutable in managed code, so the method can selectively read and change those values. 请务必记住这一点,因为它会影响为 Windows 运行时Windows Runtime 组件编写的单元测试。This is important to remember because it affects unit tests written for a Windows 运行时Windows Runtime component. 如果测试是用托管代码编写的,则在测试过程中数组的内容看起来是可变的,如果稍后从本机代码调用该方法,则结果可能会不同。If the tests are written in managed code, the contents of an array will appear to be mutable during testing, and the results are likely to be different if the method is called from native code later.

如果将此特性应用于 out 参数或具有特性的参数,则 InAttribute 在导出模块时将导致错误。Applying this attribute to an out parameter or to a parameter that has the InAttribute attribute causes an error when the module is exported. 将特性应用到具有特性的参数 OutAttribute 会导致错误,除非该参数还具有 Visual Basic ByRef 修饰符。Applying the attribute to a parameter that has the OutAttribute attribute causes an error unless the parameter also has the Visual Basic ByRef modifier. 在这种情况下,该属性是冗余的,但允许使用。In that case, the attribute is redundant but allowed.



初始化 WriteOnlyArrayAttribute 类的新实例。Initializes a new instance of the WriteOnlyArrayAttribute class.



在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)