Globals.VariableExists 속성

지정된 변수가 있는지 여부를 반환합니다.

네임스페이스:  EnvDTE
어셈블리:  EnvDTE(EnvDTE.dll)

구문

‘선언
ReadOnly Property VariableExists ( _
    Name As String _
) As Boolean
bool this[
    string Name
] { get; }
property bool VariableExists[String^ Name] {
    bool get (String^ Name);
}
abstract VariableExists : 
        Name:string -> bool with get
JScript에서는 인덱싱된 속성을 지원하지 않습니다.

매개 변수

  • Name
    형식: String

    필수입니다. 변수 이름을 나타냅니다.

속성 값

형식: Boolean
변수가 있으면 true를 나타내고 없으면 false를 나타내는 부울 값입니다.

설명

VariableValue 속성을 사용하여 변수의 값을 확인하려는 경우 이 변수가 없으면 null 값이 지정된 같은 이름의 새 변수가 만들어집니다. 빈 변수와 존재하지 않는 변수를 구분하려면 VariableExists 속성을 사용하십시오.

변수는 다음과 같은 특징을 가집니다.

  • 시스템 제한 사항 이외에는 길이에 대한 제한이 없습니다.

  • 대/소문자를 구분하지 않습니다.

  • 시스템에서 허용하는 모든 문자를 사용할 수 있습니다.

  • 문자열과 숫자 등 간단한 데이터 형식만 사용할 수 있으며 SafeArrays 또는 IDispatch 인터페이스를 사용할 수 없습니다.

예제

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

.NET Framework 보안

참고 항목

참조

Globals 인터페이스

EnvDTE 네임스페이스

기타 리소스

프로젝트 및 솔루션에 정보 유지

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행