Beispiel #1
0
        public static bool LoadConfig <T>(IConfigFile file, T value) where T : class
        {
            var config = Config.Create(file.ConfigType);

            try
            {
                var content = file.ReadAllText();
                if (!string.IsNullOrEmpty(content))
                {
                    if (value == null)
                    {
                        value = config.Deserialize <T>(content);
                    }
                    else
                    {
                        config.PopulateObject(content, value);
                        file.WriteAllText(config.Serialize(value));
                    }
                }
                else
                {
                    file.WriteAllText(config.Serialize(value));
                }
            }
            catch (ConfigDeserializingException)
            {
                file.WriteAllText(config.Serialize(value));
                return(false);
            }
            catch (ConfigSerializingException) { return(false); }

            return(true);
        }