0
我有一个自引用循环。我试着阅读和实施其他一些答案,但似乎并不奏效。我有一个类,将我的对象保存为json文件(方法)。它试图序列化对象,但为自引用循环引发异常。我正在序列化的对象是第二个块(类)。我该如何解决这个问题?它一直工作,直到我添加按钮,所以我假设我在处理程序中做了一些错误,但我真的不知道。自引用循环错误
Public Sub saveLocalSettings()
Console.WriteLine("saveLocalSettings")
If Not Directory.Exists(_SettingsFile) Then
Directory.CreateDirectory(_SettingsFile)
End If
' Try
Dim strConfigurationManager As String = JsonConvert.SerializeObject(_LocalSettings, PreserveReferencesHandling.Objects)
'Dim strConfigurationManager As String = JsonConvert.SerializeObject(_LocalSettings, Newtonsoft.Json.ReferenceLoopHandling.Ignore)
lm.writeFile(_SettingsFile + _FileName, strConfigurationManager, True)
' Catch ex As Exception
' End Try
End Sub
Imports Newtonsoft.Json
Public Class RGOSetting
Public Property id As String
Public Property title As String
Private mtbTitle As New MaskedTextBox
Public Property sharestatus As Integer
Public Property settingstring As String
Public Property userid As Integer
Public Property setting_profiles As New List(Of RGOSettingProfile)
Private rgolcm As RGOLeagueChampionManager
' Private rgolssm As RGOLeagueSumSpManager
Public btnUpdate As New Button
Public btnReset As New Button
Public btnClear As New Button
End Class
Public Class RGOSettingProfile
Public Property champion As LeagueChampion
Public Property summoner_spells As New List(Of LeagueSummonerSpell)
Public Sub New()
End Sub
Public Sub New(ByVal strChampion As String, ByVal strSummonerSpell As List(Of String))
End Sub
End Class
你到底想干什么?你不能序列化控件(至少不是这样),所以不清楚它们为什么在那里。 '_LocalSettings'是'RGOSetting'的一个实例吗?什么是'RGOSettingProfile'?你是否想做一些配置文件(多个命名配置集)? – Plutonix
是的,我有多个设置的多个设置。这些控件是动态添加到面板的,我需要添加一个处理程序来保存它。我在这里有图片:https://docs.google.com/document/d/1-0AOVbB5W589j52-LEN1wRat80jPrLTmCjtoOj0u7Pc/edit?usp=sharing。我仍然需要添加第二部分,每个冠军都会生成另一个图标面板,您可以在其中选择/取消选择对象。你可以选择任何一个冠军,每个冠军都有一个相同选项的列表。我还添加了RGOSettingProfile –
如果有3个按钮与每个事物相关联,则它们不需要是动态的 - 给定名称它们在每种情况下都做同样的事情。从用户数据中分离出用户界面的东西(数据中的东西可能会将它们映射为像文本或图像一样)。将数据链接到UI的一种方法是创建一个用户控件。当传递其中一个对象时,它会相应地显示数据。 – Plutonix