Share via


Solution2.Globals, propriété

Obtient l'objet Globals qui contient toutes valeurs de variable pouvant être enregistrées dans le fichier solution (.sln), le fichier projet ou les données de profil de l'utilisateur.

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

Syntaxe

'Déclaration
ReadOnly Property Globals As Globals
Globals Globals { get; }
property Globals^ Globals {
    Globals^ get ();
}
abstract Globals : Globals with get
function get Globals () : Globals

Valeur de propriété

Type : Globals
Objet Globals.

Notes

Les compléments sont disponibles lorsque la solution est chargée.

Les Globals ne sont pas nécessairement associés aux compléments ; ils peuvent également être associés à des macros ou à tout autre client Automation.

Exemples

Pour plus d'informations sur l'exécution de ce code de complément, consultez Comment : compiler et exécuter les exemples de code du modèle objet Automation.

L'exemple suivant ajoute une variable globale à une solution ouverte et affiche toutes les variables globales dans la solution.

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    GlobalsExample(_applicationObject)
End Sub

Sub GlobalsExample(ByVal dte As DTE2)
    ' This add-in adds a global variable to a solution and
    ' displays it.
    ' Open a solution in 
    ' Visual Studio before running this example.
    Try
        Dim soln As Solution2 =  _
        CType(_applicationObject.Solution, Solution2)
        Dim solnName As String = _
        System.IO.Path.GetFileNameWithoutExtension(soln.FullName)
        Dim globals As String = ""
        MsgBox("Adding global variable TempGlobal = ""TempValue""")
        soln.Globals.VariableValue("TempGlobal") = "TempValue"
        Dim names() As Object =  _
        CType(soln.Globals.VariableNames, Object())
        Dim name As String
        For Each name In names
            globals &= "    " & name & " = """ & _
            soln.Globals.VariableValue(name).ToString() & """" & vbCrLf
        Next
        MsgBox("Solution " & solnName & _
        " has the following global variables:" & _
        vbCrLf & vbCrLf & globals)
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
//you will need to add this reference to your project as well
using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    GlobalsExample((DTE2)_applicationObject);
}
public void GlobalsExample(DTE2 dte)
{
    // This add-in adds a global variable to the solution and 
    // displays it. 
    // Open a solution in 
    // Visual Studio before running this example.
    try
    {
        Solution2 soln = (Solution2)_applicationObject.Solution;
        string solnName =
 System.IO.Path.GetFileNameWithoutExtension(soln.FullName);
        MessageBox.Show
("Adding global variable TempGlobal = \"TempValue\"");
        soln.Globals["TempGlobal"] = "TempValue";
        object[] names = (object[])soln.Globals.VariableNames; 
        string globals = "";
        foreach (string name in names)
            globals += "    " + name + " = \"" 
+ soln.Globals[name].ToString() + "\"\n";
        MessageBox.Show("Solution " + solnName 
+ " has the following global variables:\n\n" + globals);
    }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

Sécurité .NET Framework

Voir aussi

Référence

Solution2 Interface

EnvDTE80, espace de noms

Autres ressources

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