Ejemplo n.º 1
0
        private static Dictionary <string, string> ParseContent(string fileContent)
        {
            Dictionary <string, string> keyValues = new Dictionary <string, string>();

            string[] linesArray = fileContent.Split('\n');
            foreach (string line in linesArray)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                KeyValuePair <string, string> pair = KeyValueFormatter.Disassemble(line);
                keyValues.Add(pair.Key, pair.Value);
            }
            return(keyValues);
        }
Ejemplo n.º 2
0
        public static bool WriteToFile <T>(T data, string path) where T : ISerializableData
        {
            using (FileStream stream = File.OpenWrite(path))
            {
                data.GetSerialiazableProperties().ForEach(property =>
                {
                    try
                    {
                        byte[] array = new UTF8Encoding(true)
                                       .GetBytes(KeyValueFormatter.Assemble(property.Name, property.GetValue(data).ToString()));
                        stream.Write(array, 0, array.Length);
                    }
                    catch (InvalidCastException e)
                    {
                        Console.WriteLine("InvalidCastException: {0}. Cannot cast member: {1}", e.Message, property.Name);
                    }
                });
            }

            return(true);
        }