internal void AddFileBasedSource(Func <string, SettingsSource> sourceFactory, string fileNameTemplate, bool required) { var fileName = _compositeDictionary.ExpandVariables(fileNameTemplate); var fullPath = Path.Combine(_basePath, fileName); if (File.Exists(fullPath)) { var source = sourceFactory.Invoke(fullPath); Add(source.ToSettingsDictionary()); } else if (required) { throw new FileNotFoundException("No such file", fullPath); } }
/// <summary> /// Set the environment using variable expansion /// </summary> public SettingsBuilder SetEnvironment(string environmentTemplate) { _environment = _compositeDictionary.ExpandVariables(environmentTemplate); return(this); }
/// <summary> /// Replace all occurrences of the pattern ${key} within the provided template /// if KEY has a configuration selector, ie ${key:prod} it will take precedence over the current Environment /// </summary> public string ExpandVariables(string template) => SettingsDictionary.ExpandVariables(template, Environment);