diff --git a/LangLang/Core/Repository/Serialization/Serializer.cs b/LangLang/Core/Repository/Serialization/Serializer.cs index f1c19a11..3737df68 100644 --- a/LangLang/Core/Repository/Serialization/Serializer.cs +++ b/LangLang/Core/Repository/Serialization/Serializer.cs @@ -1,13 +1,42 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace LangLang.Core.Repository.Serialization { - internal class Serializer + class Serializer where T : ISerializable, new() { + private const char Delimiter = '|'; + public string ToCSV(List objects) + { + StringBuilder sb = new StringBuilder(); + + foreach (ISerializable obj in objects) + { + string line = string.Join(Delimiter.ToString(), obj.ToCSV()); + sb.AppendLine(line); + } + + return sb.ToString(); + } + + public List FromCSV(IEnumerable lines) + { + List objects = new List(); + + foreach (string line in lines) + { + string[] csvValues = line.Split(Delimiter); + T obj = new T(); + obj.FromCSV(csvValues); + objects.Add(obj); + } + + return objects; + } } }