ReadOnlyArrayAttribute 类

定义

当应用于 Windows 运行时组件中的数组参数时,指定传递到该参数的数组的内容仅用于输入。When applied to an array parameter in a Windows Runtime component, specifies that the contents of the array that is passed to that parameter are used only for input. 调用方期望此数组不因调用而更改。The caller expects the array to be unchanged by the call.

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

注解

如果组件中的数组参数 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.

重要

具有属性的参数的 ReadOnlyArrayAttribute 行为不同,具体取决于调用方是使用本机代码编写还是用托管代码编写的。Parameters that have the ReadOnlyArrayAttribute attribute behave differently depending on whether the caller is written in native code or managed code. 如果调用方是 (JavaScript 或 Visual C++ 组件扩展) 的本机代码,则当调用跨越应用程序二进制接口 (ABI) 边界时,会复制该数组。If the caller is native code (JavaScript or Visual C++ component extensions), the array is copied when the call crosses the application binary interface (ABI) boundary. 元素在必要时会进行转换。Elements are converted if necessary. 因此,方法对只可输入数组进行的任何意外更改都对调用方不可见。Therefore, any accidental changes the method makes to an input-only array are not visible to the caller.

如果调用方是托管代码,则不会复制该数组。If the caller is managed code, the array is not copied. 原始数组可用于被调用方法,就像在 .NET Framework 的任何方法调用中一样。The original array is available to the called method, as it would be in any method call in the .NET Framework. 数组内容在 .NET Framework 代码中是可变的,因此方法对数组进行的任何更改都对调用方可见。Array contents are mutable in .NET Framework code, so any changes the method makes to the array are visible to the caller. 请务必记住这一点,因为它会影响为 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.

如果将此特性应用于具有或特性的参数,则 InAttribute OutAttribute 会在导出模块时导致错误。Applying this attribute to a parameter that has the InAttribute or OutAttribute attribute causes an error when the module is exported. 将特性应用于 out 参数也会导致错误。Applying the attribute to an out parameter also causes an error.

构造函数

ReadOnlyArrayAttribute()

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

属性

TypeId

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

(继承自 Attribute)

方法

Equals(Object)

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

(继承自 Attribute)
GetHashCode()

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

(继承自 Attribute)
GetType()

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

(继承自 Object)
IsDefaultAttribute()

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

(继承自 Attribute)
Match(Object)

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

(继承自 Attribute)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回表示当前对象的字符串。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)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(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)

适用于

另请参阅