private static void DemonstrateTextFileStorage() { var people = new List <Person>(); var logs = new List <LogEntry>(); string peopleFile = @"C:\Users\racol\OneDrive\Desktop\C# Learning\Learning_C#\Learning-.NET\Generics\Generics\people.csv"; string logFile = @"C:\Users\racol\OneDrive\Desktop\C# Learning\Learning_C#\Learning-.NET\Generics\Generics\logs.csv"; PopulateLists(people, logs); /* New way of doing things - generics! */ GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile); GenericTextFileProcessor.SaveToTextFile <LogEntry>(logs, logFile); var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person>(peopleFile); foreach (var p in newPeople) { Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); } Console.WriteLine(); var newLogs = GenericTextFileProcessor.LoadFromTextFile <LogEntry>(logFile); foreach (var log in newLogs) { Console.WriteLine($"{ log.ErrorCode }: { log.Message } at { log.TimeOfEvent.ToShortTimeString() }"); } /* Old way of doing things - non-generics! */ //OriginalTextFileProcessor.SaveLogs(logs, logFile); //var newLogs = OriginalTextFileProcessor.LoadLogs(logFile); //foreach (var log in newLogs) //{ // Console.WriteLine($"{ log.ErrorCode }: { log.Message } at { log.TimeOfEvent.ToShortTimeString() }"); //} //OriginalTextFileProcessor.SavePeople(people, peopleFile); //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile); //foreach (var p in newPeople) //{ // Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); //} }
private static void DemonstrateTextFileStorage() { List <Person> people = new List <Person> (); List <LogEntry> logs = new List <LogEntry> (); string peopleFile = @"./people.csv"; string logFile = @"./logs.csv"; PopulateLists(people, logs); /* New way of doing things - generics */ GenericTextFileProcessor.SaveToTextFile <Person> (people, peopleFile); GenericTextFileProcessor.SaveToTextFile <LogEntry> (logs, logFile); var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person> (peopleFile); foreach (var p in newPeople) { Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); } var newLogs = GenericTextFileProcessor.LoadFromTextFile <LogEntry> (logFile); foreach (var l in newLogs) { Console.WriteLine($"{ l.ErrorCode }: { l.Message } at { l.TimeOfEvent.ToShortTimeString() }"); } /* Old way of doing things - non generics */ // OriginalTextFileProcessor.SaveLogs (logs, logFile); // var newLogs = OriginalTextFileProcessor.LoadLogs (logFile); // foreach (var l in newLogs) { // Console.WriteLine ($"{ l.ErrorCode }: { l.Message } at { l.TimeOfEvent.ToShortTimeString() }"); // } //OriginalTextFileProcessor.SavePeople (people, peopleFile); // var newPeople = OriginalTextFileProcessor.LoadPeople (peopleFile); // foreach (var p in newPeople) { // Console.WriteLine ($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); // } }
private static void DemonstrateTextFileStorage() { List <Person> people = new List <Person>(); List <LogEntry> logs = new List <LogEntry>(); string peopleFile = @"C:\Temp\people.csv"; string logFile = @"C:\Temp\logs.csv"; PopulateLists(people, logs); /* With Generics (good way of doing) */ // instead of copy-paste and configure methods inside we have like OriginalTextFileProcessor // we can use generic method like this example. // if we have another model, not a problem. We dont need to configure another method for it. // GenericTextFileProcessor configures for all list types. GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile); GenericTextFileProcessor.SaveToTextFile <LogEntry>(logs, logFile); var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person>(peopleFile); foreach (var p in newPeople) { Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); } var newLogs = GenericTextFileProcessor.LoadFromTextFile <LogEntry>(logFile); foreach (var log in newLogs) { Console.WriteLine($"{log.ErrorCode} : {log.Message} at {log.TimeOfEvent.ToShortTimeString()}"); } /* Without Generics (bad way of doing) */ //OriginalTextFileProcessor.SavePeople(people, peopleFile); //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile); //foreach (var p in newPeople) //{ // Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); //} //OriginalTextFileProcessor.SaveLogs(logs,logFile); //var newLogs = OriginalTextFileProcessor.LoadLogs(logFile); //foreach (var log in newLogs) //{ // Console.WriteLine($"{log.ErrorCode} : {log.Message} at {log.TimeOfEvent.ToShortTimeString()}"); //} }
private static void DemonstrateTextFileStorage() { List <Person> people = new List <Person>(); List <LogEntry> logs = new List <LogEntry>(); string peopleFile = @"C:\Users\mindaugas.pikelis\source\repos\Generics\people.txt"; string logFile = @"C:\Users\mindaugas.pikelis\source\repos\Generics\logs.txt"; PopulateLists(people, logs); /* New way of doing things - generics */ GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile); GenericTextFileProcessor.SaveToTextFile <LogEntry>(logs, logFile); var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person>(peopleFile); foreach (var p in newPeople) { Console.WriteLine($"{ p.FirstName} { p.LastName } (IsAlive = { p.IsAlive })"); } var newLogs = GenericTextFileProcessor.LoadFromTextFile <LogEntry>(logFile); foreach (var log in newLogs) { Console.WriteLine($"{ log.ErrorCode }: { log.Message } at { log.TimeOfEvent.ToShortTimeString() })"); } /* Old way of doing things - non-generics */ //OriginalTextFileProcessor.SavePeople(people, peopleFile); //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile); //foreach (var p in newPeople) //{ // Console.WriteLine($"{ p.FirstName} { p.LastName } (IsAlive = { p.IsAlive })"); //} }
static void Main(string[] args) { Console.WriteLine("Press ENTER to start!"); Console.ReadKey(); List <Person> people = new List <Person>(); List <Log> logs = new List <Log>(); var peopleFile = @"C:\Users\JEAN-NOTE\AppData\Local\Temp\people.txt"; var logFile = @"C:\Users\JEAN-NOTE\AppData\Local\Temp\log.txt"; PopulateLists(people, logs); /* New way of doing things - generics */ GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile); GenericTextFileProcessor.SaveToTextFile <Log>(logs, logFile); var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person>(peopleFile); foreach (var p in newPeople) { Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })"); } var newLogs = GenericTextFileProcessor.LoadFromTextFile <Log>(logFile); foreach (var log in newLogs) { Console.WriteLine($"{ log.ErrorCode }: { log.Message } at { log.TimeOfEvent.ToShortTimeString() }"); } Console.WriteLine("Press ENTER to complete"); Console.ReadKey(); }