Share via


Globals.VariableValue, propriété

Retourne ou définit la variable avec le nom spécifié.

Espace de noms :  EnvDTE
Assembly :  EnvDTE (dans EnvDTE.dll)

Syntaxe

'Déclaration
Default Property VariableValue ( _
    VariableName As String _
) As Object
    Get
    Set
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 ne prend pas en charge les propriétés indexées.

Paramètres

  • VariableName
    Type : System.String
    Obligatoire.Chaîne représentant le nom de la variable à récupérer.

Valeur de propriété

Type : System.Object
Objet représentant la variable.

Notes

Si vous essayez de récupérer une variable qui n'existe pas, la variable est créée avec une valeur vide. Si vous essayez de définir une variable qui n'existe pas, elle est créée avec la valeur spécifiée.

Notes

Les noms de chaînes VariableValue ne peuvent pas contenir les caractères suivants : espace, signe deux-points (:) ou point (.) Si un nom contient un de ces caractères, le message d'erreur « La valeur n'est pas comprise dans la plage attendue » s'affiche.

Exemples

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.");
}

Sécurité .NET Framework

Voir aussi

Référence

Globals Interface

EnvDTE, espace de noms

Autres ressources

Persistance d'informations dans des projets et des solutions

Comment : compiler et exécuter les exemples de code du modèle objet Automation