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。) | |
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();
}
}
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
请参见
参考
Microsoft.VisualStudio.Tools.Applications 命名空间