Ejemplo n.º 1
0
        public static Persistent <T> Load(string path, bool saveIfNew = true)
        {
            var config = new Persistent <T>(path, new T());

            if (File.Exists(path))
            {
                using (var f = File.OpenRead(path))
                {
                    var reader = new StreamReader(f);
                    config.Data = JsonConvert.DeserializeObject <T>(reader.ReadToEnd());
                }
            }
            else if (saveIfNew)
            {
                config.Save(path);
            }

            return(config);
        }
Ejemplo n.º 2
0
        public static Persistent <T> Load(string path, bool saveIfNew = true)
        {
            var config = new Persistent <T>(path, new T());

            if (File.Exists(path))
            {
                var ser = new XmlSerializer(typeof(T));
                using (var f = File.OpenRead(path))
                {
                    config.Data = (T)ser.Deserialize(f);
                }
            }
            else if (saveIfNew)
            {
                config.Save(path);
            }

            return(config);
        }