次の方法で共有


CachedDataItem クラス

Visual Studio で Office 開発ツールを使用して作成されたドキュメント レベルのカスタマイズにおいて、キャッシュ データ オブジェクトを表します。

継承階層

System.Object
  Microsoft.VisualStudio.Tools.Applications.CachedDataNodeBase
    Microsoft.VisualStudio.Tools.Applications.CachedDataItem

名前空間:  Microsoft.VisualStudio.Tools.Applications
アセンブリ:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll 内)

構文

'宣言
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class CachedDataItem _
    Inherits CachedDataNodeBase
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class CachedDataItem : CachedDataNodeBase

CachedDataItem 型で公開されるメンバーは以下のとおりです。

プロパティ

  名前 説明
パブリック プロパティ DataType キャッシュされたデータ オブジェクトの型のアセンブリ修飾名を取得または設定します。
パブリック プロパティ Id CachedDataItem によって表される、キャッシュされたデータ オブジェクトの名前を取得または設定します。
パブリック プロパティ Schema CachedDataItem によって表されるキャッシュ データ オブジェクトが DataSet または DataTable である場合に、そのキャッシュ データ オブジェクトを説明するスキーマを取得または設定します。
パブリック プロパティ Xml CachedDataItem によって表される、キャッシュされたデータ オブジェクトの XML 表記を取得または設定します。

このページのトップへ

メソッド

  名前 説明
パブリック メソッド Equals 指定した Object が、現在の Object と等しいかどうかを判断します。 (Object から継承されます。)
プロテクト メソッド Finalize オブジェクトがガベージ コレクションにより収集される前に、そのオブジェクトがリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。)
パブリック メソッド GetHashCode 特定の型のハッシュ関数として機能します。 (Object から継承されます。)
パブリック メソッド GetType 現在のインスタンスの Type を取得します。 (Object から継承されます。)
プロテクト メソッド MemberwiseClone 現在の Object の簡易コピーを作成します。 (Object から継承されます。)
パブリック メソッド SerializeDataInstance データを CachedDataItem によって表されるキャッシュ データ オブジェクトとしてシリアル化します。
パブリック メソッド ToString 現在のオブジェクトを表す文字列を返します。 (Object から継承されます。)

このページのトップへ

解説

ドキュメント レベルのカスタマイズにおけるデータのキャッシュの詳細については、「キャッシュされたデータ」および「サーバー上のドキュメント内のデータへのアクセス」を参照してください。

次のコード例では、Excel ブックのデータ キャッシュに格納されている各 CachedDataItem を調べ、それぞれのキャッシュ データ オブジェクトの名前を表示します。

この例には、次の項目が必要です。

  • コンソール アプリケーション プロジェクトまたはその他の Office 以外のプロジェクト。

  • 次のアセンブリへの参照。

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll および Microsoft.VisualStudio.Tools.Applications.Runtime.dll (プロジェクトが .NET Framework 4 を対象とする場合)。

      または

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll および Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (プロジェクトが .NET Framework 3.5 を対象とする場合)。

  • コード ファイルの先頭に、Microsoft.VisualStudio.Tools.Applications 名前空間および Microsoft.VisualStudio.Tools.Applications.Runtime 名前空間に対する Imports ステートメント (Visual Basic の場合) または using ステートメント (C# の場合) を追加します。

Private Sub DisplayDataCacheContents(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 stringBuilder1 As New System.Text.StringBuilder()

            ' Display all of the cached data items 
            ' in the document.
            Dim hostItem1 As CachedDataHostItem
            For Each hostItem1 In serverDocument1.CachedData.HostItems
                stringBuilder1.Append(vbLf & "Namespace and class: ")
                stringBuilder1.Append(hostItem1.Id & vbLf)
                Dim dataItem1 As CachedDataItem
                For Each dataItem1 In hostItem1.CachedData
                    stringBuilder1.Append("     Data item: ")
                    stringBuilder1.Append(dataItem1.Id & vbLf)
                Next dataItem1
            Next hostItem1
            MessageBox.Show(stringBuilder1.ToString())
        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 DisplayDataCacheContents(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);
            System.Text.StringBuilder stringBuilder1 =
                new System.Text.StringBuilder();

            // Display all of the cached data items 
            // in the document.
            foreach (CachedDataHostItem hostItem1 in
                serverDocument1.CachedData.HostItems)
            {
                stringBuilder1.Append("\nNamespace and class: ");
                stringBuilder1.Append(hostItem1.Id + "\n");
                foreach (CachedDataItem dataItem1 in
                    hostItem1.CachedData)
                {
                    stringBuilder1.Append("     Data item: ");
                    stringBuilder1.Append(dataItem1.Id + "\n");
                }
            }
            MessageBox.Show(stringBuilder1.ToString());
        }
        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();
    }
}

スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバーは、スレッド セーフです。 インスタンス メンバーの場合は、スレッド セーフであるとは限りません。

参照

参照

Microsoft.VisualStudio.Tools.Applications 名前空間

その他の技術情報

ServerDocument クラスによるサーバー上のドキュメントの管理

キャッシュされたデータ

サーバー上のドキュメント内のデータへのアクセス