Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Globals.VariableValue Property

Returns or sets the variable with the specified name.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)
Object this[
	string VariableName
] { get; set; }

Parameters

VariableName
Type: System.String

Required. A string representing the name of the variable to retrieve.

Property Value

Type: System.Object
An object representing the variable.

If you attempt to retrieve a variable that does not exist, the variable is created with an empty value. If you attempt to set a variable that does not exist, it is created with the specified value.

NoteNote

VariableValue name strings cannot contain space, colon (:), or period(.) characters. If a name has any of these characters, you get the error, "Value does not fall within expected range."

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.");
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.