我有一个IList类,但是当我尝试将它们存储在IsolatedStorage中时,它只是说内置的seralizer无法处理它,JSON.net也不能。我已经把课程放在下面,任何人都可以想出一种方法来存储它?在独立存储中存储IList
我得到的错误是;
类型'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";
}
}
你需要一个具体的类 - 你不能序列化的界面,据我所知 – Charleh 2012-07-06 18:40:54
在具体的类研究后,它看起来像什么,我贴的? – Purify 2012-07-06 18:43:36
没有接口是实现的契约 - 它定义的行为不是状态 - 具体的类是提供实现的类。任何接口都不是可序列化的(尽管我假设你正在序列化整个列表......不仅仅是一个项目,因为ScoreWatcher是具体的--IList不是) –
Charleh
2012-07-06 18:47:57