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 | 如果快取資料物件為 DataSet 或 DataTable,取得或設定結構描述,說明 CachedDataItem 所表示的快取資料物件名稱。 | |
Xml | 取得或設定 CachedDataItem 所表示之快取資料物件名稱的 XML 表示。 |
回頁首
方法
名稱 | 說明 | |
---|---|---|
Equals | 判斷指定的物件是否等於目前物件。 (繼承自 Object)。 | |
GetHashCode | 做為特定型別的雜湊函式。 (繼承自 Object)。 | |
GetType | 取得目前執行個體的 Type。 (繼承自 Object)。 | |
SerializeDataInstance | 將資料序列化為 CachedDataItem 所表示的快取資料物件。 | |
ToString | 傳回表示目前物件的字串。 (繼承自 Object)。 |
回頁首
備註
如需快取文件層級自訂中的資料之詳細資訊,請參閱快取資料和存取伺服器文件中的資料。
範例
下列程式碼範例會檢查 Excel 活頁簿資料快取中的每個 CachedDataItem,並顯示每個快取資料物件名稱。
這個範例需要:
主控台應用程式專案或其他非 Office 專案。
下列組件的參考:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll
Microsoft.VisualStudio.Tools.Applications.Runtime.dll
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();
}
}
執行緒安全
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。不保證任何執行個體成員是安全執行緒。
請參閱
參考
Microsoft.VisualStudio.Tools.Applications 命名空間