Globals.VariableValue (Propiedad)
Actualización: noviembre 2007
Devuelve o establece la variable que tiene el nombre especificado.
Espacio de nombres: EnvDTE
Ensamblado: EnvDTE (en EnvDTE.dll)
Sintaxis
Default Property VariableValue ( _
VariableName As String _
) As Object
Dim instance As Globals
Dim VariableName As String
Dim value As Object
value = instance(VariableName)
instance(VariableName) = value
Object this[
string VariableName
] { get; set; }
property Object^ default[String^ VariableName] {
Object^ get (String^ VariableName);
void set (String^ VariableName, Object^ value);
}
JScript no admite propiedades indizadas.
Parámetros
VariableName
Tipo: System.StringNecesario. Cadena que representa el nombre de la variable que se recuperará.
Valor de propiedad
Tipo: System.Object
Objeto que representa la variable.
Comentarios
Si se intenta recuperar una variable inexistente, se crea la variable con un valor vacío. Si se intenta establecer una variable inexistente, se crea la variable con el valor especificado.
Nota: |
---|
Las cadenas de nombre de VariableValue no pueden contener los caracteres de espacio, dos puntos (:) ni punto (.). Si un nombre tiene cualquiera de estos caracteres, obtendrá el error "El valor no está dentro del intervalo esperado". |
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.");
}
Permisos
- Plena confianza para el llamador inmediato. Un código de confianza parcial no puede utilizar este miembro. Para obtener más información, vea Utilizar bibliotecas de código que no es de plena confianza.
Vea también
Referencia
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