Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Simple Protobuf-net code failing in MonoDroid with 'No serializer defined for type'
  2. [ProtoContract]
  3. public class SSDTO {
  4.     [ProtoMember(1)]
  5.     public Dictionary<string, string> Strings = new Dictionary<string, string>(50);
  6.  
  7.     [ProtoMember(2)]
  8.     public Dictionary<string, int> Ints = new Dictionary<string, int>(50);
  9.  
  10.     [ProtoMember(3)]
  11.     public Dictionary<string, byte[]> Bytes = new Dictionary<string, byte[]>(10);
  12. }
  13.  
  14. public class SettingStore {
  15.     public event EventHandler ContentsChanged;
  16.  
  17.     private Dictionary<string, string> _StringVals;
  18.     private Dictionary<string, int> _IntVals;
  19.     private Dictionary<string, byte[]> _ByteVals;
  20.  
  21.     public SettingStore() {
  22.         _StringVals = new Dictionary<string, string>(50);
  23.         _IntVals = new Dictionary<string, int>(50);
  24.         _ByteVals = new Dictionary<string, byte[]>(10);
  25.     }
  26.  
  27.     private SettingStore(SSDTO source) {
  28.         _StringVals = source.Strings;
  29.         _IntVals = source.Ints;
  30.         _ByteVals = source.Bytes;
  31.     }
  32.        
  33. public static SettingStore DeSerialize(Stream data) {
  34.         return new SettingStore(Serializer.Deserialize<SSDTO>(data));
  35.     }
  36.  
  37.     public void Serialize(Stream Target) {
  38.         Serializer.Serialize<SSDTO>(Target, toDTO());
  39.     }
  40.  
  41.     private SSDTO toDTO() {
  42.         return new SSDTO { Ints = this._IntVals, Strings = this._StringVals, Bytes = this._ByteVals };
  43.     }
  44.  
  45. }