Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<T> Parse<T>(string path) where T : DbAccessible
- {
- var output = new List<T>();
- using (StreamReader sr = new StreamReader(path))
- {
- string line;
- while ((line = sr.ReadLine()) != null)
- {
- var data = line.Split(' ');
- if (typeof(T) == typeof(User))
- {
- string country = data[4];
- if (data.Length == 7)
- country += data[5];
- output.Add((T)(DbAccessible)new User
- {
- Id = int.Parse(data[0]),
- Name = data[1],
- LastName = data[2],
- Age = int.Parse(data[3]),
- Country = (Country)Enum.Parse(typeof(Country), country),
- Gender = (Gender)Enum.Parse(typeof(Gender), data[data.Length - 1])
- });
- }
- else
- {
- output.Add((T)(DbAccessible)new Appeal
- {
- Id = int.Parse(data[0]),
- Date = DateTime.ParseExact(data[1], "dd.MM.yyyy", CultureInfo.InvariantCulture),
- Content = data[2],
- UserId = int.Parse(data[3])
- });
- }
- }
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement