关于Silverlight IsolatedStorage 不能Serialze Parameter[]

手上项目需要保存 DomianDataSource的QueryName和Parameters, 当客户按F5后,读出这两个参数,加载数据。

解决办法:

          是应用IsolatedStorage将这两个参数保存到客户本地。

问题:使用下面代码

           IsolatedStorageSettings.ApplicationSettings["parameters"] =parameters;

根本就无法把parameters保存到本地。

解决办法:IsolatedStorageSettings 可以保存DictionaryEntry[]。简单添加两个扩展方法,转化一下就ok.

 public static DictionaryEntry[] ToDictionaryEntry(this Parameter[] parameters)
        {
            if (parameters == null || parameters.Length == 0)
                return null;
            DictionaryEntry[] result = new DictionaryEntry[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                DictionaryEntry de = new DictionaryEntry(parameters[i].ParameterName, parameters[i].Value);
                result[i] = de;
            }
            return result;
        }

        public static Parameter[] ToParameters(this DictionaryEntry[] des)
        {
            if (des == null || des.Length == 0)
                return null;
            Parameter[] result = new Parameter[des.Length];
            for (int i = 0; i < des.Length; i++)
            {
                Parameter p = new Parameter { ParameterName = des[i].Key.ToString(), Value = des[i].Value };
                result[i] = p;
            }
            return result;
        }

原文地址:https://www.cnblogs.com/mjgb/p/1892082.html