Condividi tramite


Proprietà CachedDataItem.DataType (System 2007)

Aggiornamento: novembre 2007

Ottiene o imposta il nome qualificato dall'assembly del tipo di oggetto dati memorizzato.

Spazio dei nomi:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

Sintassi

Public Property DataType As String

Dim instance As CachedDataItem
Dim value As String

value = instance.DataType

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

Valore proprietà

Tipo: System.String

Nome qualificato dall'assembly del tipo di oggetto dati memorizzato.

Note

La proprietà DataType restituisce un nome qualificato dall'assembly del tipo di oggetto dati memorizzato utile per creare una nuova istanza di un tipo personalizzato presente nella cache di dati. Ad esempio, è possibile ottenere il Type di un tipo di dati personalizzato passando il nome qualificato dall'assembly del tipo al metodo GetType. Sarà quindi possibile creare un'istanza del tipo personalizzato passando il Type come parametro al metodo Activator.CreateInstance.

Per ulteriori informazioni sul formato della stringa del tipo con qualificazione di assembly restituita dalla proprietà DataType, vedere la proprietà Type.AssemblyQualifiedName.

Esempi

Nell'esempio di codice seguente viene utilizzato il metodo SerializeDataInstance per modificare il valore di una stringa memorizzata nella cache in un foglio di lavoro di una cartella di lavoro di Excel. Il codice utilizza la proprietà DataType per verificare che l'oggetto dati memorizzato nella cache sia una stringa prima di tentare di modificarlo.

In questo esempio è necessario specificare all'inizio del file di codice un riferimento agli assembly Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll e le istruzioni Imports, in Visual Basic, o using, in C#, per gli spazi dei nomi Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime. Nell'esempio si presuppone inoltre che la cartella di lavoro specificata includa una personalizzazione con una classe Sheet1 nello spazio dei nomi ExcelWorkbook1 e una stringa memorizzata nella cache della classe Sheet1 denominata 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();
    }
}

Autorizzazioni

Vedere anche

Riferimenti

CachedDataItem Classe

Membri CachedDataItem

Spazio dei nomi Microsoft.VisualStudio.Tools.Applications