Compartilhar via


CachedDataItem.DataType A propriedade (sistema de 2007)

Obtém ou define o nome qualificado por conjunto do tipo de objeto de dados em cache.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (em Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

Sintaxe

Public Property DataType As String

Dim instance As CachedDataItem
Dim value As String

value = instance.DataType

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

Valor de propriedade

Tipo: System.String
O nome qualificado de assembly do tipo de objeto de dados em cache.

Comentários

The DataType propriedade retorna um nome de assembly qualificado do tipo de dados em cache que é útil para criar uma nova instância de um tipo personalizado que está no cache de dados. Por exemplo, você pode obter o Type um tipo de dados personalizados, passando o nome de tipo qualificado de assembly para o GetType método. Você pode, em seguida, cria uma instância do tipo personalizado, passando esse Type sistema autônomo um parâmetro para o Activator.CreateInstance método.

Para obter detalhes sobre o formato da seqüência de caracteres de tipo qualificado de assembly retornado pelo DataType propriedade, consulte o Type.AssemblyQualifiedName propriedade.

Exemplos

O exemplo de código a seguir usa o SerializeDataInstance método para modificar o valor de uma seqüência de caracteres armazenados em cache em uma planilha de uma pasta de trabalho do Excel. O código usa o DataType propriedade para verificar se o objeto de dados em cache é uma seqüência de caracteres antes de tentar modificá-lo.

Este exemplo requer uma referência aos assemblies Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll e Microsoft.VisualStudio.Tools.Applications.tempo de execução.v9.0.dll e Imports (para Visual Basic) ou using (para translation from VPE for Csharp) instruções para Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime espaços para nome na parte superior do seu arquivo de código. Este exemplo também assume que a pasta de trabalho especificada tem uma personalização com um Sheet1 classe na ExcelWorkbook1 namespace e uma seqüência de caracteres em cache na Sheet1 classe chamada CachedString.

PrivateSub ModifyCachedString(ByVal documentPath AsString)
    Dim runtimeVersion AsInteger = 0
    Dim serverDocument1 As ServerDocument = NothingTry
        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.")
            ReturnEndIfIf 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 IsNotNothingAndAlso _
                Type.GetType(dataItem1.DataType).Equals(GetType(String)) Then

                dataItem1.SerializeDataInstance("This is the new cached string value.")
                serverDocument1.Save()
            EndIfElse
            MessageBox.Show("The specified document does not have cached data.")
        EndIfCatch 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.")
    FinallyIfNot (serverDocument1 IsNothing) Then
            serverDocument1.Close()
        EndIfEndTryEndSub
privatevoid 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();
    }
}

Permissões

Consulte também

Referência

CachedDataItem Classe

Membros CachedDataItem

Namespace Microsoft.VisualStudio.Tools.Applications