-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBank.cs
43 lines (39 loc) · 1.13 KB
/
DBank.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Newtonsoft.Json;
using System;
using System.IO;
namespace winf
{
class DBank
{
public static void SerializeUsers(LinkedList<User> UserList)
{
string path = "UserBank.json";
using (StreamWriter sw = File.CreateText(path))
{
foreach (User user in UserList)
{
string User = JsonConvert.SerializeObject(user);
sw.WriteLine(User);
}
}
}
public static LinkedList<User> DeserializeUsers()
{
string path = "UserBank.json";
if (File.Exists(path))
{
LinkedList<User> UsersList = new LinkedList<User>();
var lines = File.ReadLines("UserBank.json");
foreach (var line in lines)
{
UsersList.Push(JsonConvert.DeserializeObject<User>(line));
}
return UsersList;
}
else
{
throw new InvalidOperationException("There is no such file");
}
}
}
}