CachedDataItem.DataType Özellik
Alır veya önbelleğe alınmış verileri nesne türü derleme nitelikli adını ayarlar.
Ad alanı: Microsoft.VisualStudio.Tools.Applications
Derleme: Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll içinde)
Sözdizimi
'Bildirim
Public Property DataType As String
Get
Set
public string DataType { get; set; }
Özellik Değeri
Tür: System.String
Önbelleğe alınmış veri nesnesi türü derleme nitelikli adı.
Açıklamalar
DataType Özelliği özel bir türü olan veri önbelleği yeni bir örneğini oluşturmak için yararlıdır önbelleğe alınmış veri türü derleme nitelikli adını döndürür Örneğin, get Type türü derleme nitelikli adı tarafından özel veri türü GetType yöntemi. Daha sonra bu ileterek özel türünün bir örneği oluşturabilirsiniz Type parametre olarak Activator.CreateInstance yöntemi.
Tarafından döndürülen türü derleme nitelikli dizenin biçimi hakkında ayrıntılı bilgi için DataType özelliği, bkz: Type.AssemblyQualifiedName özelliği.
Örnekler
Aşağıdaki kod örneği SerializeDataInstance bir çalışma sayfasında bir Excel çalışma kitabı önbelleğe bir dize değerini değiştirme yöntemi Kodu kullanır DataType özelliği, önbelleğe alınmış veri nesnesi olan bir dize değiştirme it. denemeden önce doğrulamak için
Bu örnek aşağıdakileri gerektirir:
Belge düzeyinde özelleştirme içeren Excel bir Sheet1 , sınıf ExcelWorkbook1 ad ve önbelleğe alınmış bir dize Sheet1 sınıf adlı CachedString.
Bir konsol uygulaması projesi veya başka bir Office dışı projeye.
Aşağıdaki derlemelerine başvurular:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.dll (eğer proje .NET Framework 4'i hedefliyorsa).
ya da
Microsoft.Visualstudio.Tools.Applications.ServerDocument.V10.0.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (, proje hedefleri.net Framework 3.5).
Imports(Visual Basic için) veya using (için C#) ifadeleri için Microsoft.VisualStudio.Tools.Applications ve Microsoft.VisualStudio.Tools.Applications.Runtime ad alanları üst kod dosyası.
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();
}
}
.NET Framework Güvenliği
- Anında arayanlar için tam güven. Bu üye kısmen güvenilen kodla kullanılamaz. Daha fazla bilgi için bkz. kısmen güvenilir kod tarafından Kitaplıklar kullanma.