CachedDataItem.DataType 속성 (2007 시스템)

업데이트: 2007년 11월

캐시된 데이터 개체 형식의 어셈블리로 한정된 이름을 가져오거나 설정합니다.

네임스페이스:  Microsoft.VisualStudio.Tools.Applications
어셈블리:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0(Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

구문

Public Property DataType As String

Dim instance As CachedDataItem
Dim value As String

value = instance.DataType

instance.DataType = value
public string DataType { get; set; }

속성 값

형식: System.String

캐시된 데이터 개체 형식의 어셈블리로 한정된 이름입니다.

설명

DataType 속성은 데이터 캐시에 있는 사용자 지정 형식의 새 인스턴스를 만드는 데 유용한 캐시된 데이터 형식의 어셈블리로 한정된 이름을 반환합니다. 예를 들어, 사용자 지정 데이터 형식의 Type은 어셈블리로 한정된 형식 이름을 GetType 메서드로 가져올 수 있습니다. 그런 다음 이 TypeActivator.CreateInstance 메서드에 매개 변수로 전달하여 사용자 지정 형식의 인스턴스를 만들 수 있습니다.

DataType 속성에서 반환되는 어셈블리로 한정된 형식 문자열의 형식에 대한 자세한 내용은 Type.AssemblyQualifiedName 속성을 참조하십시오.

예제

다음 코드 예제에서는 SerializeDataInstance 메서드를 사용하여 Excel 통합 문서의 워크시트에 캐시된 문자열의 값을 수정합니다. 문자열의 값을 수정하기 전에 이 코드에서는 DataType 속성을 사용하여 캐시된 데이터 개체가 문자열인지 확인합니다.

이 예제를 사용하려면 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll과 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll 어셈블리에 대한 참조, Microsoft.VisualStudio.Tools.ApplicationsMicrosoft.VisualStudio.Tools.Applications.Runtime 네임스페이스에 대한 Imports(Visual Basic) 또는 using(C#) 문을 코드 파일 맨 위에 추가해야 합니다. 또한 이 예제에서는 지정된 통합 문서에 ExcelWorkbook1 네임스페이스의 Sheet1 클래스를 사용하는 사용자 지정이 있고 Sheet1 클래스에는 CachedString이라는 캐시된 문자열이 있다고 가정합니다.

Private Sub ModifyCachedString(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion <> 3 Then
            MessageBox.Show("This document does not have a Visual Studio Tools for Office " & _
                "customization, or it has a customization that was created with a version of " & _
                "the runtime that is incompatible with this version of the ServerDocument class.")
            Return
        End If

        If ServerDocument.IsCacheEnabled(documentPath) Then
            serverDocument1 = New ServerDocument(documentPath)
            Dim hostItem1 As CachedDataHostItem = _
                serverDocument1.CachedData.HostItems("ExcelWorkbook1.Sheet1")
            Dim dataItem1 As CachedDataItem = hostItem1.CachedData("CachedString")

            If dataItem1 IsNot Nothing AndAlso _
                Type.GetType(dataItem1.DataType).Equals(GetType(String)) Then

                dataItem1.SerializeDataInstance("This is the new cached string value.")
                serverDocument1.Save()
            End If
        Else
            MessageBox.Show("The specified document does not have cached data.")
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Finally
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
private void ModifyCachedString(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);

        if (runtimeVersion != 3)
        {
            MessageBox.Show("This document does not have a Visual Studio Tools for " +
                "Office customization, or it has a customization that was created with " +
                "a version of the runtime that is incompatible with this version of the " +
                "ServerDocument class.");
            return;
        }

        if (ServerDocument.IsCacheEnabled(documentPath))
        {
            serverDocument1 = new ServerDocument(documentPath);
            CachedDataHostItem hostItem1 = 
                serverDocument1.CachedData.HostItems["ExcelWorkbook1.Sheet1"];
            CachedDataItem dataItem1 = hostItem1.CachedData["CachedString"];

            if (dataItem1 != null &&
                Type.GetType(dataItem1.DataType) == typeof(string))
            {
                dataItem1.SerializeDataInstance("This is the new cached string value.");
                serverDocument1.Save();
            }
        }
        else
        {
            MessageBox.Show("The specified document does not have cached data.");
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

권한

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

CachedDataItem 클래스

CachedDataItem 멤버

Microsoft.VisualStudio.Tools.Applications 네임스페이스