ReturnValueNameAttribute 类

定义

指定 Windows 运行时组件中方法的返回值名称。Specifies the name of the return value of a method in a Windows Runtime component.

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

注解

Windows 运行时Windows Runtime 组件中,方法的所有参数和返回值都必须具有名称。In a Windows 运行时Windows Runtime component, all the parameters of a method and the return value must have names. 默认情况下, Winmdexp.exe (Windows 运行时元数据导出工具) 将返回值命名为 "value"。By default, Winmdexp.exe (Windows Runtime Metadata Export Tool) gives the return value the name "value". 当你在使用 JavaScript 编写的应用中使用组件时 Windows 8.x 应用商店Windows 8.x Store ,可以使用此名称来检索返回值。When you use a component in a Windows 8.x 应用商店Windows 8.x Store app written in JavaScript, you can use this name to retrieve the return value. 例如,假设某个组件定义了一个方法,该方法具有一个返回值和两个 out 参数 (ByRef 参数 OutAttribute Visual Basic) :For example, suppose a component defines a method that has a return value and two out parameters (ByRef parameters with the OutAttribute attribute in Visual Basic):

public static int ComputeAverage([ReadOnlyArray()] int[] input,  
    out int minValue, out int maxValue)  
{  
    …  
}  
Public Shared Function ComputeAverage( _  
        <ReadOnlyArray()> ByVal input As Integer, _  
        <Out()> ByRef minValue As Integer, _  
        <Out()> ByRef maxValue As Integer) As Integer  
    …  
End Function  

从 JavaScript 调用函数时,可以通过默认名称 () 来访问返回值 valueWhen you call the function from JavaScript, you can access the return value by its default name (value):

var data = [5, 13, 23, 37];  
var results = SampleComponent.TestStuff.computeAverage(data);  
var formattedResults = "Min=" + results.minValue + ", Avg=" +   
    results.value + ", Max=" + results.maxValue;  

如果已经有一个名为 "value" 的参数,则必须为返回值指定不同的名称。 或者,您可能只想使用一个更有意义的名称 (例如,在此示例) 中为 "平均值"。Or you might simply want to use a more meaningful name (such as "average" in this example). 将特性应用于 ReturnValueNameAttribute 方法,并指定新名称。Apply the ReturnValueNameAttribute attribute to your method and specify a new name.

[return: ReturnValueName("average")]  
public static int ComputeAverage([ReadOnlyArray()] int[] input,  
    out int minValue, out int maxValue)  
{  
    …  
}  
Public Shared Function ComputeAverage( _  
        <ReadOnlyArray()> ByVal input As Integer, _  
        <Out()> ByRef minValue As Integer, _  
        <Out()> ByRef maxValue As Integer) _  
            As <ReturnValueName("average")> Integer  
    …  
End Function  

构造函数

ReturnValueNameAttribute(String)

初始化 ReturnValueNameAttribute 类的新实例,并指定返回值的名称。Initializes a new instance of the ReturnValueNameAttribute class, and specifies the name of the return value.

属性

Name

获取 Windows 运行时Windows Runtime 组件中为方法返回值指定的名称。Gets the name that was specified for the return value of a method in a Windows 运行时Windows Runtime component.

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)

适用于

另请参阅