// Create a new instance of the SettingsContext class SettingsContext context = new SettingsContext(); // Set the current application context context["Application"] = "MyApp"; // Set the current user context context["User"] = "JohnDoe"; // Use the context information to retrieve application settings string mySetting = Properties.Settings.Default.MySetting;
// Create a new instance of the SettingsContext class SettingsContext context = new SettingsContext(); // Set the current application context context["Application"] = "MyApp"; // Set the current user context context["User"] = "JohnDoe"; // Get the configuration settings for the current context Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); // Get the application settings section for the current context ApplicationSettingsSection appSettings = (ApplicationSettingsSection)config.GetSection("applicationSettings"); // Use the application settings section to retrieve a setting for the current context string mySetting = appSettings.Settings["MySetting"].Value;In this example, we again create a new instance of SettingsContext and set some context data. We then use this context information to retrieve a setting from the application's config file. We do this by opening the configuration file using the ConfigurationManager class and accessing the appropriate section and setting using the SettingsContext.