DefaultSettingValueAttribute Class
Specifies the default value for an application settings property.
Assembly: System (in System.dll)
Important Note: |
|---|
DefaultSettingValueAttribute can only be applied to individual settings properties; it is invalid to apply this attribute to an entire application settings class. |
Different settings providers may have different requirements or limitations on the use of the DefaultSettingValueAttribute. For example, the LocalFileSettingsProvider does not require this attribute, and will override any value provided by this attribute if there are any values—default or user-modified— already present in the data store.
DefaultSettingValueAttribute requires that the default value can be represented as a string. As a result, settings using XML serialization cannot have a default value specified by means of this attribute. Some providers may choose to support multiple serialization schemes which can be specified at compile time using the SettingsSerializeAsAttribute.
Caution: |
|---|
The default values specified by this attribute are stored as plain text in the resultant compiled .exe or .dll file. Therefore these default values are inherently insecure. |
The following code example demonstrates the use of the DefaultSettingValueAttribute applied to three of the four properties of the FormSettings wrapper class, which is derived from the ApplicationSettingsBase class. This class is used to persist the location, size, background color, and text of form. The first three of these form properties have default values associated with them.
The full code example is listed in the ApplicationSettingsBase class overview.
'Application settings wrapper class. This class defines the settings we intend to use in our application. NotInheritable Class FormSettings Inherits ApplicationSettingsBase <UserScopedSettingAttribute()> _ Public Property FormText() As String Get Return CStr(Me("FormText")) End Get Set(ByVal value As String) Me("FormText") = value End Set End Property <UserScopedSettingAttribute(), DefaultSettingValueAttribute("0, 0")> _ Public Property FormLocation() As Point Get Return CType(Me("FormLocation"), Point) End Get Set(ByVal value As Point) Me("FormLocation") = value End Set End Property <UserScopedSettingAttribute(), DefaultSettingValueAttribute("225, 200")> _ Public Property FormSize() As Size Get Return CType(Me("FormSize"), Size) End Get Set(ByVal value As Size) Me("FormSize") = value End Set End Property <UserScopedSettingAttribute(), DefaultSettingValueAttribute("LightGray")> _ Public Property FormBackColor() As Color Get Return CType(Me("FormBackColor"), Color) End Get Set(ByVal value As Color) Me("FormBackColor") = value End Set End Property End Class
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Important Note: