Пример #1
0
 private Note DeserializeNote(SerializedNote note)
 {
     return(new Note()
     {
         Id = note.Id,
         Content = note.Content,
         Date = note.Date,
         Category = SerializedCategory.DeserializeCategory(note.Category)
     });
 }
Пример #2
0
 public static Category DeserializeCategory(SerializedCategory category)
 {
     return(new Category()
     {
         Id = category.Id,
         Name = category.Name,
         BackgroundColor = category.BackgroundColor,
         FontColor = category.FontColor,
         IsDefault = category.IsDefault
     });
 }
Пример #3
0
        private void Serialize()
        {
            List <SerializedCategory> categories = new List <SerializedCategory>();

            foreach (Category category in _categories)
            {
                categories.Add(SerializedCategory.SerializeCategory(category));
            }
            using (FileStream fs = File.Open(_file, FileMode.OpenOrCreate))
            {
                (new BinaryFormatter()).Serialize(fs, categories);
            }
        }
Пример #4
0
 private void Deserialize()
 {
     if (File.Exists(_file))
     {
         try
         {
             using (FileStream fs = File.Open(_file, FileMode.Open))
             {
                 List <SerializedCategory> list = (List <SerializedCategory>)(new BinaryFormatter()).Deserialize(fs);
                 _categories.Clear();
                 foreach (SerializedCategory item in list)
                 {
                     _categories.Add(SerializedCategory.DeserializeCategory(item));
                 }
             }
         }catch (Exception e)
         {
             Debug.Log(e.Message);
             File.Delete(_file);
         }
     }
 }