簡體   English   中英

將列表保存到IsolatedStorageSettings

[英]Save List to IsolatedStorageSettings

我有這個課:

class LyricsItem
{
    public LyricsItem()
    {

    }

    public LyricsItem(LyricsItem item)
    {
        this.searchUrl = item.searchUrl;
        this.croppingRegex = item.croppingRegex;
    }

    private string _searchUrl;
    private string _croppingRegex;

    public string searchUrl
    {
        get { return _searchUrl; }
        set { _searchUrl = value; }
    }

    public string croppingRegex
    {
        get { return _croppingRegex; }
        set { _croppingRegex = value; }
    }
}

這是帶有LyricsItem數組:

public List<LyricsItem> lyricsArray;

這是我將項目添加到數組的方式:

    LyricsItem item = new LyricsItem();

    item.croppingRegex = croppingRegex;
    item.searchUrl = searchurl;

    lyricsArrayTmp.Add(item);

我想將其添加到IsolatedStorageSettings

        IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
        if (appSettings.Contains("lyricsData"))
        {
            appSettings["lyricsData"] = lyricsArray;
        }
        else
        {
            appSettings.Add("lyricsData", lyricsArray);
        }

        appSettings.Save();

但是當我保存IsolatedStorageSettings時,出現以下異常:

The collection data contract type 'System.Collections.Generic.List`1[[**********, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' cannot be deserialized because it does not have a public parameterless constructor. Adding a public parameterless constructor will fix this error. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members - see documentation for more details

您無法在ApplicationSettings中序列化私有類。 聲明為公開:

public class LyricsItem
{
    public LyricsItem()
    {

    }

    public LyricsItem(LyricsItem item)
    {
        this.searchUrl = item.searchUrl;
        this.croppingRegex = item.croppingRegex;
    }

    private string _searchUrl;
    private string _croppingRegex;

    public string searchUrl
    {
        get { return _searchUrl; }
        set { _searchUrl = value; }
    }

    public string croppingRegex
    {
        get { return _croppingRegex; }
        set { _croppingRegex = value; }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM