Proprietà Solution3.Globals

ottiene Globals oggetto contenente tutti i valori variabili che possono essere salvati nel file di soluzione (sln), nel file di progetto, o nei dati di profilo.

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

Sintassi

'Dichiarazione
ReadOnly Property Globals As Globals
Globals Globals { get; }
property Globals^ Globals {
    Globals^ get ();
}
abstract Globals : Globals
function get Globals () : Globals

Valore proprietà

Tipo: EnvDTE.Globals
In Globals oggetto.

Note

I componenti aggiuntivi è disponibile quando la soluzione, file di progetto e così via, viene caricata.

Globals non essere necessariamente associato ai componenti aggiuntivi; possono essere associati alle macro o qualsiasi altro client di automazione.

Esempi

Per informazioni su come eseguire il codice del componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

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 Solution3 =  _
        CType(_applicationObject.Solution, Solution3)
        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
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
    {
        Solution3 soln = (Solution3)_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);
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Solution3 Interfaccia

Overload Globals

Spazio dei nomi EnvDTE90

Altre risorse

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