Advertisement
olegstankoptev

Untitled

May 22nd, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. public static List<T> Parse<T>(string path) where T : DbAccessible
  2.         {
  3.             var output = new List<T>();
  4.             using (StreamReader sr = new StreamReader(path))
  5.             {
  6.                 string line;
  7.                 while ((line = sr.ReadLine()) != null)
  8.                 {
  9.                     var data = line.Split(' ');
  10.                     if (typeof(T) == typeof(User))
  11.                     {
  12.                         string country = data[4];
  13.                         if (data.Length == 7)
  14.                             country += data[5];
  15.                         output.Add((T)(DbAccessible)new User
  16.                         {
  17.                             Id = int.Parse(data[0]),
  18.                             Name = data[1],
  19.                             LastName = data[2],
  20.                             Age = int.Parse(data[3]),
  21.                             Country = (Country)Enum.Parse(typeof(Country), country),
  22.                             Gender = (Gender)Enum.Parse(typeof(Gender), data[data.Length - 1])
  23.                         });
  24.                     }
  25.                     else
  26.                     {
  27.                         output.Add((T)(DbAccessible)new Appeal
  28.                         {
  29.                             Id = int.Parse(data[0]),
  30.                             Date = DateTime.ParseExact(data[1], "dd.MM.yyyy", CultureInfo.InvariantCulture),
  31.                             Content = data[2],
  32.                             UserId = int.Parse(data[3])
  33.                         });
  34.                     }
  35.                 }
  36.             }
  37.             return output;
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement