我有一個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