/// <summary>
        /// Load and deserialize data from configuration
        /// </summary>
        /// <returns></returns>
        public T Load()
        {
            var file = GetFilePath(FileName) ?? CreateAppConfig();
            var data = File.ReadAllText(file);

            return(_serializer.Deserialize(data));
        }
Exemple #2
0
        public static Config Load(Stream stream, IConfigSerializer serializer)
        {
            Config config;

            using (stream)
                config = serializer.Deserialize(stream);

            return(config);
        }
Exemple #3
0
        public static Config Load(string fileName, IConfigSerializer serializer)
        {
            Config config;

            if (File.Exists(fileName))
            {
                using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    config = serializer.Deserialize(fs);
            }
            else
            {
                config = new Config();
            }

            config._filePath = fileName;
            return(config);
        }
 /// <summary>
 /// Deserializes a string to a configuration.
 /// </summary>
 /// <typeparam name="T">The type of the configuration.</typeparam>
 /// <param name="serializer"></param>
 /// <param name="config">The string representation of the configuration.</param>
 /// <returns>The deserialized configuration.</returns>
 public static T Deserialize <T>(this IConfigSerializer serializer, string config) where T : class, IConfig => (T)serializer.Deserialize(config, typeof(T));
 public IConfig LoadConfig(string pathToConfigFile)
 {
     return(configSerializer.Deserialize(fileSystem.File.ReadAllText(pathToConfigFile)));
 }