Właściwość Globals.VariableValue —

Zwraca lub ustawia zmienną o określonej nazwie.

Przestrzeń nazw:  EnvDTE
Zestaw:  EnvDTE (w EnvDTE.dll)

Składnia

'Deklaracja
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 : 
        VariableName:string -> Object with get, set
Język JScript nie obsługuje właściwości indeksowanych.

Parametry

  • VariableName
    Typ: String

    Wymagane.Ciąg znaków reprezentujący nazwę zmiennej do pobrania.

Wartość właściwości

Typ: Object
Obiekt reprezentujący zmiennej.

Uwagi

Próba pobrania zmienna, która nie istnieje zmienna jest utworzona z pustą wartość.Jeśli spróbujesz ustawić zmienną, która nie istnieje, jest tworzony z określonej wartości.

[!UWAGA]

VariableValueciągi nazwa nie może zawierać przestrzeń, dwukropek (:) lub znaki period(.).Jeśli nazwa zawiera żadnego z tych znaków, komunikat o błędzie, "Wartość nie wchodzą w zakres oczekiwanego".

Przykłady

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

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

Globals Interfejs

Przestrzeń nazw EnvDTE

Inne zasoby

Przechowywanie informacji w projektach i rozwiązaniach

Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady