Condividi tramite


ReturnValueNameAttribute Classe

Definizione

Specifica il nome del valore restituito di un metodo in un componente Windows Runtime.

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

Commenti

In un componente Windows Runtime tutti i parametri di un metodo e il valore restituito devono avere nomi. Per impostazione predefinita, Winmdexp.exe (strumento di esportazione metadati Windows Runtime) assegna al valore restituito il nome "value". Quando usi un componente in un'app store Windows 8.x scritta in JavaScript, puoi usare questo nome per recuperare il valore restituito. Si supponga, ad esempio, che un componente definisca un metodo con un valore restituito e due parametri /out (parametri ByRef con l'attributo OutAttribute 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

Quando si chiama la funzione da JavaScript, è possibile accedere al valore restituito in base al nome predefinito (value):

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

Se si dispone già di un parametro denominato "value", è necessario assegnare un nome diverso al valore restituito. In alternativa, è sufficiente usare un nome più significativo, ad esempio "media" in questo esempio. Applicare l'attributo ReturnValueNameAttribute al metodo e specificare un nuovo nome.

[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

Costruttori

Nome Descrizione
ReturnValueNameAttribute(String)

Inizializza una nuova istanza della ReturnValueNameAttribute classe e specifica il nome del valore restituito.

Proprietà

Nome Descrizione
Name

Ottiene il nome specificato per il valore restituito di un metodo in un componente Windows Runtime.

TypeId

Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute.

(Ereditato da Attribute)

Metodi

Nome Descrizione
Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per questa istanza.

(Ereditato da Attribute)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

Quando sottoposto a override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da Attribute)

Si applica a