简体   繁体   English

将列表保存到IsolatedStorageSettings

[英]Save List to IsolatedStorageSettings

I have this class : 我有这个课:

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; }
    }
}

And this is Array with items LyricsItem : 这是带有LyricsItem数组:

public List<LyricsItem> lyricsArray;

This is how i add items to the array : 这是我将项目添加到数组的方式:

    LyricsItem item = new LyricsItem();

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

    lyricsArrayTmp.Add(item);

And i want to add it to IsolatedStorageSettings : 我想将其添加到IsolatedStorageSettings

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

        appSettings.Save();

But When i get to save the IsolatedStorageSettings i get this exception: 但是当我保存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

You can't serialize a private class in the ApplicationSettings. 您无法在ApplicationSettings中序列化私有类。 Declare it as public instead: 声明为公开:

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.

相关问题 如何将IsolatedStorageSettings密钥保存到字符串 - How to save IsolatedStorageSettings key to a string Isolatedstoragesettings.applicationsettings.save不保存 - Isolatedstoragesettings.applicationsettings.save does not save 将接口类型对象保存到IsolatedStorageSettings中,进行序列化 - Save interface type object to IsolatedStorageSettings, serialization wp7 isolatedstoragesettings.save是否再次重写了整个数据 - does wp7 isolatedstoragesettings.save rewrites the whole data again 带隔离存储设置的 FormatException - FormatException with IsolatedStorageSettings 绑定到IsolatedStorageSettings - Binding to IsolatedStorageSettings 我是否需要在Windows Phone应用程序中调用IsolatedStorageSettings.Save方法? - Do I need to call IsolatedStorageSettings.Save method in windows phone application? 如何在设置页面中设置列表选择器并从IsolatedStorageSettings存储和检索值?(内部描述) - How to set List picker in settings page and store and retrieve value from IsolatedStorageSettings?(Descriptions Inside) 从IsolatedStorageSettings中检索设置 - Retreving settings from IsolatedStorageSettings 在IsolatedStorageSettings中恢复计数 - Resume Count in IsolatedStorageSettings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM