Condividi tramite


Proprietà Globals.VariableValue

Restituisce o imposta la variabile con il nome specificato.

Spazio dei nomi:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Sintassi

'Dichiarazione
Default Property VariableValue ( _
    VariableName As String _
) As Object
Object this[
    string VariableName
] { get; set; }
property Object^ default[String^ VariableName] {
    Object^ get (String^ VariableName);
    void set (String^ VariableName, Object^ value);
}
abstract VariableValue : Object with get, set
JScript non supporta le proprietà indicizzate.

Parametri

  • VariableName
    Tipo: System.String
    obbligatorio.Stringa che rappresenta il nome della variabile per recuperare.

Valore proprietà

Tipo: System.Object
un oggetto che rappresenta la variabile.

Note

Se si tenta di recuperare una variabile che non esiste, la variabile viene creato con un valore vuoto.Se si tenta di impostare una variabile che non esiste, viene creata con il valore specificato.

[!NOTA]

VariableValue le stringhe del nome non possono contenere uno spazio, i due punti (:), o i caratteri di punto (.).Se il nome è uno di questi caratteri, viene generato l'errore, “valore non fa parte dell'intervallo previsto.„

Esempi

Sub OnAddinLoaded(ByVal dte As DTE)
    ' Count the number of times an add-in is loaded
    ' and store the value in the solution.
    Dim globals As Globals
    globals = dte.Solution.Globals
    If globals.VariableExists("AddinLoadCounter") Then
        ' The counter has already been set, so increment it.
        Dim int32 As System.Int32
        int32 = System.Int32.Parse(CStr(globals("AddinLoadCounter")))
        int32 += 1
        globals("AddinLoadCounter") = int32.ToString()
    Else
        ' Counter has never been set, so create and initialize it.
        globals("AddinLoadCounter") = 1.ToString()
        globals.VariablePersists("AddinLoadCounter") = True
    End If
    MsgBox("This add-in has been loaded: " & _
    globals.VariableValue("AddinLoadCounter") & " times.")
End Sub
void OnAddinLoaded(_DTE applicationObject)
{
    // Count the number of times an add-in is loaded
    // and store the value in the solution.
    Globals globals;
    globals = applicationObject.Solution.Globals;
    if(globals.get_VariableExists("AddinLoadCounter"))
    {
        // The counter has already been set, so increment it.
        System.Int32 int32;
        int32 = System.Int32.Parse((string)
        globals["AddinLoadCounter"]);
        int32++;
        globals["AddinLoadCounter"] = int32.ToString();
    }
    else
    {
        // Counter has never been set, so create and initialize it.
        globals["AddinLoadCounter"] = 1.ToString();
        globals.set_VariablePersists("AddinLoadCounter", true);
    }
    System.Windows.Forms.MessageBox.Show("This add-in has been loaded: 
    " + globals.VariableValue["AddinLoadCounter"] + " times.");
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Globals Interfaccia

Spazio dei nomi EnvDTE

Altre risorse

Mantenimento delle informazioni in progetti e soluzioni

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione