Beispiel #1
0
        private void GetTimeSpanButton_Click(object sender, EventArgs e)
        {
            var backupTime = TimeSpan.Parse(ConfigurationManager.AppSettings["BackupTime"]);

            Console.WriteLine($"TimeSpan.Parse: {backupTime}");

            var testModeGeneric1 = AppConfiguration.GetConfigSetting <TimeSpan>("BackupTime");

            Console.WriteLine($"GetConfigSetting: {testModeGeneric1}");

            try
            {
                var testModeGeneric2 = AppConfiguration.ConfigSetting <TimeSpan>("BackupTime");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                var anotherTest = AppConfiguration.ConvertOrDefault <TimeSpan>(ConfigurationManager.AppSettings["BackupTime"]);
                Console.WriteLine(anotherTest);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #2
0
        private void GetStringButton_Click(object sender, EventArgs e)
        {
            var testModeConventional = ConfigurationManager.AppSettings["DatabaseServer"];

            Console.WriteLine($"Get TestMode conventional: {testModeConventional}");

            var databaseServerWrapper = AppConfiguration.DatabaseServer;

            Console.WriteLine($"Get Wrapper: {databaseServerWrapper}");

            var databaseServerGeneric = AppConfiguration.ConfigSetting <string>("DatabaseServer");

            Console.WriteLine($"Get generic: {databaseServerGeneric}");
        }
Beispiel #3
0
        private void GetBoolButton_Click(object sender, EventArgs e)
        {
            // conventional access to a setting
            var testModeConventional = Convert.ToBoolean(ConfigurationManager.AppSettings["TestMode"]);

            Console.WriteLine($"Get TestMode conventional: {testModeConventional}");

            // generic access to a setting
            var testModeGeneric1 = AppConfiguration.ConfigSetting <bool>("TestMode");

            Console.WriteLine($"Get TestMode generic: {testModeGeneric1}");

            // generic access to a setting with wrapper
            var testModeGeneric2 = AppConfiguration.TestMode;

            Console.WriteLine($"Get TestMode generic wrapper: {testModeGeneric2}");

            var testModeGeneric3 = AppConfiguration.TestMode1;

            Console.WriteLine(testModeGeneric3);
        }