Esempio n. 1
0
        // mix it up.
        private static IConfigurationSource LoadConfigurationSources4()
        {
            string baseDirectory       = AppDomain.CurrentDomain.BaseDirectory;
            string defaultSettingsFile = Path.Combine(baseDirectory, "default.xml");
            string customSettingsFile  = Path.Combine(baseDirectory, "custom.ini");
            string devSettingsFile     = Path.Combine(baseDirectory, "dev.config");

            IConfigurationSource defaultSettings = XmlConfigurationSource.FromFile(defaultSettingsFile);
            IConfigurationSource customSettings  = IniConfigurationSource.FromFile(customSettingsFile);
            IConfigurationSource devSettings     = DotNetConfigurationSource.FromFile(devSettingsFile);

            defaultSettings.Merge(customSettings);
            defaultSettings.Merge(devSettings);
            defaultSettings.ExpandKeyValues();
            return(defaultSettings);
        }
        public void CanLoadFromFile()
        {
            string xml = XmlConfigurationSource.ToXml(SectionGenerator.GetThreeSections());

            var source = new XmlConfigurationSource(xml)
            {
                FileName = "CanLoadFromFile.xml"
            };

            source.Save();

            var    sourceFromFile       = XmlConfigurationSource.FromFile("CanLoadFromFile.xml");
            string sourceString         = source.ToString();
            string sourceFromFileString = sourceFromFile.ToString();

            Assert.Equal(sourceString, sourceFromFileString);
        }
Esempio n. 3
0
        private static IConfigurationSource GetSource(string fileName)
        {
            IConfigurationSource source;

            switch (Extension)
            {
            case ".ini":
                source = IniConfigurationSource.FromFile(fileName);
                break;

            case ".xml":
                source = XmlConfigurationSource.FromFile(fileName);
                break;

            case ".config":
                source = DotNetConfigurationSource.FromFile(fileName);
                break;

            default:
                source = IniConfigurationSource.FromFile(fileName);
                break;
            }
            return(source);
        }