System.Runtime.InteropServices.WindowsRuntime.ReturnValueNameAttribute Class

Specifies the name of the return value of a method in a wrt component.

See Also: ReturnValueNameAttribute Members

Syntax

[System.AttributeUsage(System.AttributeTargets.Delegate | System.AttributeTargets.ReturnValue | System.AttributeTargets.All, AllowMultiple=false, Inherited=false)]
public sealed class ReturnValueNameAttribute : Attribute

Remarks

In a wrt component, all the parameters of a method and the return value must have names. By default, Winmdexp.exe (Windows Runtime Metadata Export Tool) gives the return value the name "value". When you use a component in a win8_appname_long app written in JavaScript, you can use this name to retrieve the return value. For example, suppose a component defines a method that has a return value and two out parameters (ByRef parameters with the System.Runtime.InteropServices.OutAttribute attribute in Visual Basic):

Example

public static int ComputeAverage([ReadOnlyArray()] int[] input,
    out int minValue, out int maxValue)
{
    …
}

Example

Public Shared Function ComputeAverage( _
        <ReadOnlyArray()> ByVal input As Integer, _
        <Out()> ByRef minValue As Integer, _
        <Out()> ByRef maxValue As Integer) As Integer
    …
End Function

When you call the function from JavaScript, you can access the return value by its default name (value):

Example

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

You must give the return value a different name if you already have a parameter named "value". Or you might simply want to use a more meaningful name (such as "average" in this example). Apply the System.Runtime.InteropServices.WindowsRuntime.ReturnValueNameAttribute attribute to your method and specify a new name.

Example

[return: ReturnValueName("average")]
public static int ComputeAverage([ReadOnlyArray()] int[] input,
    out int minValue, out int maxValue)
{
    …
}

Example

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

Requirements

Namespace: System.Runtime.InteropServices.WindowsRuntime
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 4.0.0.0