Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
DefaultSettingValueAttribute Class

Note: This class is new in the .NET Framework version 2.0.

Specifies the default value for an application settings property.

Namespace: System.Configuration
Assembly: System (in system.dll)

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Property)> _
Public NotInheritable Class DefaultSettingValueAttribute
    Inherits Attribute
Visual Basic (Usage)
Dim instance As DefaultSettingValueAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Property)] 
public sealed class DefaultSettingValueAttribute : Attribute
C++
[AttributeUsageAttribute(AttributeTargets::Property)] 
public ref class DefaultSettingValueAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Property) */ 
public final class DefaultSettingValueAttribute extends Attribute
JScript
AttributeUsageAttribute(AttributeTargets.Property) 
public final class DefaultSettingValueAttribute extends Attribute
NoteImportant:

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 noteCaution

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.

C#
//Application settings wrapper class
sealed class FormSettings : ApplicationSettingsBase
{
    [UserScopedSettingAttribute()]
    public String FormText
    {
        get { return (String)this["FormText"]; 
        set { this["FormText"] = value; 
    

    [UserScopedSetting()]
    [DefaultSettingValueAttribute("0, 0")]
    public Point FormLocation
    {
        get { return (Point)(this["FormLocation"]); 
        set { this["FormLocation"] = value; 
    

    [UserScopedSetting()]
    [DefaultSettingValueAttribute("225, 200")]
    public Size FormSize
    {
        get { return (Size)this["FormSize"]; 
        set { this["FormSize"] = value; 
    

    [UserScopedSetting()]
    [DefaultSettingValueAttribute("LightGray")]
    public Color FormBackColor
    {
        get { return (Color)this["FormBackColor"]; 
        set { this["FormBackColor"] = value; 
    

C++
//Application settings wrapper class
ref class FormSettings sealed: public ApplicationSettingsBase
{
public:
    [UserScopedSettingAttribute()]
    property String^ FormText
    {
        String^ get()
        {
            return (String^)this["FormText"];
        
        void set( String^ value )
        {
            this["FormText"] = value;
        
    

public:
    [UserScopedSetting()]
    [DefaultSettingValueAttribute("0, 0")]
    property Point FormLocation
    {
        Point get()
        {
            return (Point)(this["FormLocation"]);
        
        void set( Point value )
        {
            this["FormLocation"] = value;
        
    

public:
    [UserScopedSetting()]
    [DefaultSettingValueAttribute("225, 200")]
    property Size FormSize
    {
        Size get()
        {
            return (Size)this["FormSize"];
        
        void set( Size value )
        {
            this["FormSize"] = value;
        
    

public:
    [UserScopedSetting()]
    [DefaultSettingValueAttribute("LightGray")]
    property Color FormBackColor
    {
        Color get()
        {
            return (Color)this["FormBackColor"];
        
        void set(Color value)
        {
            this["FormBackColor"] = value;
        
    

;
System.Object
   System.Attribute
    System.Configuration.DefaultSettingValueAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker