public void Deserialize(string serializedString)
        {
            var lines = serializedString.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                try {
                    Add(SerializeableFactory.FromString <T>(line));
                } catch (Exception ex) {
                    throw ex as DeserializationException;
                }
            }
        }
Exemple #2
0
        public static T Read <T>(string filename) where T : ISerializeable, new()
        {
            var filecontent = "";

            // TODO: Read contents from filename into filecontent using StreamReader!

            if (!string.IsNullOrEmpty(filecontent))
            {
                try {
                    return(SerializeableFactory.FromString <T>(filecontent));
                } catch (Exception ex) {
                    throw ex;
                }
            }
            throw new SerializationException("Couldn't read file!");
        }
Exemple #3
0
        public static T Read <T>(string filename) where T : ISerializeable, new()
        {
            var filecontent = "";

            using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                using (var sr = new StreamReader(fs))
                {
                    filecontent = sr.ReadToEnd();
                }
            }

            if (!string.IsNullOrEmpty(filecontent))
            {
                try {
                    return(SerializeableFactory.FromString <T>(filecontent));
                } catch (Exception ex) {
                    throw ex;
                }
            }
            throw new SerializationException("Couldn't read file!");
        }