Compartir a través de


Globals.VariableExists (Propiedad)

Indica si la variable especificada existe.

Espacio de nombres:  EnvDTE
Ensamblado:  EnvDTE (en EnvDTE.dll)

Sintaxis

'Declaración
ReadOnly Property VariableExists ( _
    Name As String _
) As Boolean
bool this[
    string Name
] { get; }
property bool VariableExists[String^ Name] {
    bool get (String^ Name);
}
abstract VariableExists : bool
JScript no admite propiedades indizadas.

Parámetros

  • Name
    Tipo: System.String
    Obligatorio.Representa el nombre de la variable.

Valor de propiedad

Tipo: System.Boolean
Valor Boolean que indica true si la variable existe o false si no existe.

Comentarios

Si se intenta comprobar el valor de una variable con la propiedad VariableValue y la variable no existe, se crea una variable nueva de dicho nombre con un valor nulo.Para distinguir entre una variable vacía y una variable inexistente, se debe utilizar la propiedad VariableExists.

Las variables:

  • No tienen limitación en cuanto a longitud, salvo las limitaciones propias del sistema.

  • No distinguen mayúsculas de minúsculas.

  • Pueden contener cualquier tipo de caracteres permitido por el sistema.

  • Están limitadas a tipos de datos simples, como cadenas y números.No se pueden utilizar las interfaces SafeArrays o IDispatch.

Ejemplos

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

Seguridad de .NET Framework

Vea también

Referencia

Globals Interfaz

EnvDTE (Espacio de nombres)

Otros recursos

Guardar información en proyectos y soluciones

Cómo: Compilar y ejecutar los ejemplos de código del modelo de objetos de automatización