コード例 #1
0
        /// <summary>
        /// Loads configuration values from the source represented by this <see cref="T:Microsoft.Extensions.Configuration.IConfigurationProvider" />.
        /// </summary>
        public void Load()
        {
            Data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (var config in _innerConfig.AsEnumerable())
            {
                var newValue = config.Value;
                if (!string.IsNullOrWhiteSpace(newValue))
                {
                    newValue = _variablePattern.Replace(newValue, (m) =>
                    {
                        var replacementValue = m.Value;
                        var variableName     = m.Groups[1].Value;
                        if (!string.IsNullOrWhiteSpace(variableName))
                        {
                            if (!string.IsNullOrEmpty(_innerConfig.GetValue <string>(config.Key + "_" + variableName)))
                            {
                                replacementValue = _innerConfig.GetValue <string>
                                                       (config.Key + "_" + variableName);
                            }
                            else if (!string.IsNullOrEmpty(_innerConfig.GetValue <string>(variableName)))
                            {
                                replacementValue = _innerConfig.GetValue <string>(variableName);
                            }
                        }
                        return(replacementValue);
                    });
                }

                Data.Add(config.Key, newValue);
            }
        }