다음을 통해 공유


Globals 인터페이스

업데이트: 2007년 11월

Globals 개체는 VariablePersists 속성을 사용하여 전체 세션뿐만 아니라 Visual Studio 환경의 각 세션이 유지되는 동안 데이터를 저장하는 캐시입니다.

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

구문

<GuidAttribute("E68A3E0E-B435-4DDE-86B7-F5ADEFC19DF2")> _
Public Interface Globals

Dim instance As Globals
[GuidAttribute("E68A3E0E-B435-4DDE-86B7-F5ADEFC19DF2")]
public interface Globals
[GuidAttribute(L"E68A3E0E-B435-4DDE-86B7-F5ADEFC19DF2")]
public interface class Globals
public interface Globals

설명

예를 들어 Globals 개체를 사용하면 프로그램을 실행할 때마다 이전 값이 유지되는 전역 변수를 설정할 수 있습니다. 또한 명령을 실행할 때마다 사용자가 정보를 입력해야 하는 경우 이 개체를 사용하여 명령의 기본값을 구현할 수 있습니다. 뿐만 아니라 지정한 횟수만큼 이 개체를 호출한 후 이 개체의 동작을 변경하는 데 이 개체를 사용할 수도 있습니다.

데이터는 Globals 개체에 이름/variant 값 쌍으로 저장됩니다. 선택적으로 VariablePersists 속성을 사용하여 이러한 이름/값 쌍을 디스크에 저장하면 Visual Studio의 여러 세션 간에 상태를 문자열로 유지할 수 있습니다.

참고:

개체 또는 SafeArrays를 포함하는 변수는 저장할 수 없습니다. 문자열로 저장할 수 있는 값은 네이티브 형식으로 저장됩니다.

추가 기능이나 매크로에서도 Globals 개체를 사용하여 Visual Studio 세션 간에 각 사용자에게 고유한 사용자 정의 데이터를 저장할 수 있습니다. 또한 Globals 개체를 사용하여 솔루션 파일(.sln)에 데이터를 저장하거나 이 파일에서 데이터를 검색할 수도 있습니다.

Globals 개체를 사용하여 저장한 값을 읽거나 저장하려면 VariableValue 속성을 사용합니다.

참고:

VariableValue 이름 문자열에는 공백, 콜론(:) 또는 마침표(.) 문자를 사용할 수 없습니다. 이름에 이러한 문자가 들어 있으면 "값이 예상 범위를 벗어났습니다."라는 오류 메시지가 나타납니다.

예제

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

참고 항목

참조

Globals 멤버

EnvDTE 네임스페이스

기타 리소스

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