예제 #1
0
        public static async Task <bool> LoadConfigAsync <T>(IConfigFile file, T value) where T : class
        {
            var config = Config.Create(file.ConfigType);

            try
            {
                var content = await file.ReadAllTextAsync();

                if (!string.IsNullOrEmpty(content))
                {
                    if (value == null)
                    {
                        value = config.Deserialize <T>(content);
                    }
                    else
                    {
                        config.PopulateObject(content, value);
                        await file.WriteAllTextAsync(config.Serialize(value));
                    }
                }
                else
                {
                    await file.WriteAllTextAsync(config.Serialize(value));
                }
            }
            catch (ConfigDeserializingException)
            {
                await file.WriteAllTextAsync(config.Serialize(value));

                return(false);
            }
            catch (ConfigSerializingException) { return(false); }

            return(true);
        }