我需要看看一個對象的屬性,我不能在我的開發機器上以適當的狀態實例化這個對象。我需要我的客戶端在她的機器上運行一些代碼,將有問題的對象序列化到磁盤,然後我可以分析該文件。我們如何序列化一個不是我們自己的自定義類的類?
這是我想要序列化的類。
System.Security.AccessControl.RegistrySecurity
這裏是我的代碼:
Private Sub SerializeRegSecurity(ByVal regKey As RegistryKey)
Try
Dim regSecurity As System.Security.AccessControl.RegistrySecurity = regKey.GetAccessControl()
Dim oXS As XmlSerializer = New XmlSerializer(GetType(System.Security.AccessControl.RegistrySecurity))
Dim oStmW As StreamWriter
Dim regDebugFilePath As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "RegDebugFile.xml")
'Serialize object to XML and write it to XML file
oStmW = New StreamWriter(regDebugFilePath)
oXS.Serialize(oStmW, regSecurity)
oStmW.Close()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
End Sub
這裏就是我在XML文件中結束:
<?xml version="1.0" encoding="utf-8"?>
任何關於如何完成我想要做的事情的想法?我們如何序列化一個不是我們自己的自定義類的類?
感謝您的任何幫助。即使是一種替代方法。
我想我會放棄這個問題。我不知道如何處理這個不屬於我的課程。 – Doug 2010-04-19 15:04:33