0

私はクラスの IList を持っていますが、それらを IsolatedStorage に格納しようとすると、組み込みのセラライザーはそれを処理できず、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";
    }
}
4

1 に答える 1

1

具体的なクラスのみをシリアライズできます

理想的には、シリアライザーに具象型を提供するように実装を変更する必要があります。これを IList にする必要がありますか?

編集:ああ、インターフェイスをシリアル化していないことがわかります-基本的に、クラスの UIElement への参照があります。XmlSerializer によって無視されるように指定する必要があります。これらのイベント ハンドラーはフォームによって処理されますか?

編集 2: 参考までに、これを行う場合は、シリアル化を行うために BinaryFormatter または XmlSerializer を使用しているかどうかに応じて、XmlIgnore 属性または NonSerialized を使用できます。

例えば

[XmlIgnore]
public int SomeProperty { get; set; }
于 2012-07-06T18:42:51.263 に答える