2011-04-03 19 views
0

我嘗試過在Google上搜索並在這裏找不到任何好東西。任何幫助,將不勝感激。將對象保存到IsolatedStorageSettings.ApplicationSetting時出現「不支持多維數組」錯誤

無論我嘗試將我自己的對象添加到用戶設置中,應用程序都會崩潰。 Game類非常簡單,有一些字符串和int屬性。如果其相關我可以更新該職位的全部細節。

無論何時設置CurrentGame1的值,它都會在保存方法上出現錯誤「不支持多維數組」的保存方法。我需要序列化對象嗎?我寧可不要的併發症,如果我能避免它

private Game CurrentGame1 
    { 
     get 
     { 
      if (IsolatedStorageSettings.ApplicationSettings.SingleOrDefault(z => z.Key == "Game1").Key == null) { 
       IsolatedStorageSettings.ApplicationSettings.Add("Game1", new Game()); 
       IsolatedStorageSettings.ApplicationSettings.Save(); 
      } 

      return IsolatedStorageSettings.ApplicationSettings["Game1"] as Game; 


     } 
     set 
     { 
      IsolatedStorageSettings.ApplicationSettings.Remove("Game1"); 
      IsolatedStorageSettings.ApplicationSettings.Add("Game1", value); 
      IsolatedStorageSettings.ApplicationSettings.Save(); 
     } 
    } 
+0

這裏的相關代碼是Game類 - 這是大概定義了一個不能自動序列化的多維數組的地方 – 2011-04-03 20:19:54

回答

2

您的多維陣列(FOO [X,Y])切換到數組的數組(FOO [X] [Y])代替。

1

你傳遞給你的任何對象都必須支持序列化(和反序列化)我猜想你定義Game的方式你沒有啓用它。

但我會推薦序列化(和反序列化)對象,因爲IsolatdStorage在內部使用DataContractSerializer,這非常慢。
如果你可以自己更快的序列化對象,然後傳遞一個簡單的類型到IsolatedStorageSettings,那麼你應該能夠獲得更好的性能。

相關問題