我有一个IList类,但是当我尝试将它们存储在IsolatedStorage时,它只是说内置的seralizer无法处理它,JSON.net也不能。我把课程放在下面,有人可以想办法存储吗?
我得到的错误是;
类型'System.Windows.UIElement'无法序列化。考虑标记 它与DataContractAttribute属性,并标记其所有 要使用DataMemberAttribute属性序列化的成员。
IList<ScoreWatcher> RecentSessions = new List<ScoreWatcher>();
public class ScoreWatcher
{
public ScoreWatcher() { }
public string SessionName = "";
public DateTime SessionCreationTime;
public DateTime SessionModificationTime;
public int Player1Total = 0;
public int Player1ScoreRollover = 0;
public int Player2Total = 0;
public int Player2ScoreRollover = 0;
public string Player1Name = "";
public string Player2Name = "";
public ListBox scoreListBox;
public string GrabFriendlyGLobal()
{
UpdateModificationTime();
return string.Format("{0}-{1}", Player1Total, Player2Total);
}
public void UpdateModificationTime()
{
SessionModificationTime = DateTime.Now;
}
public void UpdateScoringSystem()
{
UpdateModificationTime();
Player1Total = 0;
Player1ScoreRollover = 0;
Player2Total = 0;
Player2ScoreRollover = 0;
foreach (Match snookerMatch in matches)
{
if (snookerMatch.Player1Score > snookerMatch.Player2Score)
Player1Total++;
else if (snookerMatch.Player1Score == snookerMatch.Player2Score)
{
Player1Total++;
Player2Total++;
}
else
Player2Total++;
// House cleaning
Player1ScoreRollover += snookerMatch.Player1Score;
Player2ScoreRollover += snookerMatch.Player2Score;
}
}
public void LoadMatchesIntoListbox()
{
UpdateModificationTime();
scoreListBox.Items.Clear();
foreach (Match snookerMatch in matches)
scoreListBox.Items.Add(new UserControls.GameHistoryTile(snookerMatch.GlobalScore, snookerMatch.Player1Score, snookerMatch.Player2Score));
}
public List<Match> matches = new List<Match>();
public class Match
{
public int Player1Score = 0;
public int Player2Score = 0;
public string GlobalScore = "0-0";
}
}
答案 0 :(得分:1)
您只能序列化具体类
理想情况下,您需要更改实现以为序列化程序提供具体类型 - 您是否需要将其作为IList?
编辑:啊,我看到你没有序列化界面 - 基本上你在课堂上引用了一个UIElement。你需要指定它被XmlSerializer忽略 - 是由表单处理的事件处理程序吗?
编辑2:如果你想这样做,你可以使用XmlIgnore属性或NonSerialized,具体取决于你是否使用BinaryFormatter或XmlSerializer进行序列化
e.g。
[XmlIgnore]
public int SomeProperty { get; set; }