예제 #1
0
        public static void WithCustomConfigFile()
        {
            var args = new[] { "-c", "settings2.xml", "-n", "Richard" };
            var commandLineSource = new CliprConfigurationSource <Config>(args);
            // Since the XML config file is processed internally before the command
            // line source, the config filename must be generated out-of-band.
            Func <string> getConfigFileFromCommandLine =
                () => commandLineSource.Config.ConfigFile;

            var configManager = new ConfigurationManager <Config>(
                new XmlFileConfigurationSource <Config>(getConfigFileFromCommandLine)
            {
                PrimarySource = true      // Make sure command line source does not mark properties as changed
            }, commandLineSource);

            Console.WriteLine("Loading config file from {0}", getConfigFileFromCommandLine());

            Console.WriteLine(configManager.Out);

            Console.WriteLine("Since the XML file is marked as the primary source, " +
                              "the command line source is not counted when determining which " +
                              "properties have changed.");

            PrintPropertiesChanged(configManager);
        }
예제 #2
0
        public static void WithDefaultConfigFile()
        {
            var args = new string[] { };
            var commandLineSource = new CliprConfigurationSource <Config>(args);
            // Since the XML config file is processed internally before the command
            // line source, the config filename must be generated out-of-band.
            Func <string> getConfigFileFromCommandLine =
                () => commandLineSource.Config.ConfigFile;

            var configManager = new ConfigurationManager <Config>(
                new XmlFileConfigurationSource <Config>(getConfigFileFromCommandLine)
            {
                PrimarySource = true
            }, commandLineSource);

            Console.WriteLine("Loading config file from {0}", getConfigFileFromCommandLine());
            Console.WriteLine(configManager.Out);

            PrintPropertiesChanged(configManager);
        }