Exemplo n.º 1
0
 public void WriteToJsonFile(ObservableCollectionModifed <TasksClass> tasks)
 {
     using (StreamWriter writer = File.CreateText(JsonPath))
     {
         serializer.Serialize(writer, tasks);
     }
 }
Exemplo n.º 2
0
        public ObservableCollectionModifed <TasksClass> LoadTasks()
        {
            var IsExist = File.Exists(JsonPath);
            ObservableCollectionModifed <TasksClass> readTasks = new ObservableCollectionModifed <TasksClass>();

            if (IsExist)
            {
                using (StreamReader reader = File.OpenText(JsonPath))
                {
                    JsonSerializer serializer = new JsonSerializer();

                    readTasks = (ObservableCollectionModifed <TasksClass>)serializer.Deserialize(reader, readTasks.GetType());
                }
            }
            else
            {
                File.CreateText(JsonPath);
            }
            return(readTasks);
        }