CSharpTest.Net
Settings Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.AppConfig Namespace > UserSettingsSubSection Class : Settings Property

Glossary Item Box

Retrieves the collection of key/value settings

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property Settings As KeyValueConfigurationCollection
C# 
public KeyValueConfigurationCollection Settings {get;}

Example

Library/Library.Test/TestUserSettings.cs

C#Copy Code
UserSettingsSection settings = UserSettingsSection.DefaultSettings;
Assert.IsNull(settings);

Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Assert.IsNull(cfg.GetSection("userSettings"));

settings = UserSettingsSection.UserSettingsFrom(cfg);
Assert.IsNotNull(settings);
Assert.IsNotNull(settings.Settings);
Assert.IsNotNull(settings.Sections);

settings.Settings.Add("a", "b");
settings["1"] = "2";
Assert.AreEqual("2", settings["1"]);
settings["1"] = "3";
Assert.AreEqual("3", settings["1"]);
cfg.Save();

ConfigurationManager.RefreshSection("userSettings");
Assert.IsNotNull(UserSettingsSection.DefaultSettings);
Assert.AreEqual("b", UserSettingsSection.DefaultSettings["a"]);
Assert.IsNotNull(UserSettingsSection.UserSettings);
Assert.AreEqual("b", UserSettingsSection.UserSettings["a"]);

UserSettingsSection copy = new UserSettingsSection();

settings["a"] = "b";
settings["1"] = "2";
settings.Sections.Add("child.test").Settings.Add("AA", "BB");

copy.CopyFrom(settings);
Assert.AreEqual("b", settings["a"]);
Assert.AreEqual("2", settings["1"]);
Assert.AreEqual("BB", settings.Sections["child.test"]["AA"]);
VB.NETCopy Code
Dim settings As UserSettingsSection = UserSettingsSection.DefaultSettings
Assert.IsNull(settings)

Dim cfg As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
Assert.IsNull(cfg.GetSection("userSettings"))

settings = UserSettingsSection.UserSettingsFrom(cfg)
Assert.IsNotNull(settings)
Assert.IsNotNull(settings.Settings)
Assert.IsNotNull(settings.Sections)

settings.Settings.Add("a", "b")
settings("1") = "2"
Assert.AreEqual("2", settings("1"))
settings("1") = "3"
Assert.AreEqual("3", settings("1"))
cfg.Save()

ConfigurationManager.RefreshSection("userSettings")
Assert.IsNotNull(UserSettingsSection.DefaultSettings)
Assert.AreEqual("b", UserSettingsSection.DefaultSettings("a"))
Assert.IsNotNull(UserSettingsSection.UserSettings)
Assert.AreEqual("b", UserSettingsSection.UserSettings("a"))

Dim copy As New UserSettingsSection()

settings("a") = "b"
settings("1") = "2"
settings.Sections.Add("child.test").Settings.Add("AA", "BB")

copy.CopyFrom(settings)
Assert.AreEqual("b", settings("a"))
Assert.AreEqual("2", settings("1"))
Assert.AreEqual("BB", settings.Sections("child.test")("AA"))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys