Canonical ConfigurationProperty Example

I am trying to use the .NET configuration and understand user sections, elements, etc.

It seems that implementing these custom sections requires explicit declaration of getters and setters, which generally leads to bloat code.

For instance:

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

In particular, it seems to us necessary to explicitly return and set things in the get and set methods.

// Create a "remoteOnly" attribute.
[ConfigurationProperty("remoteOnly", DefaultValue = "false", IsRequired = false)]
public Boolean RemoteOnly
{
  get
  { 
    return (Boolean)this["remoteOnly"]; 
  }
  set
  { 
    this["remoteOnly"] = value; 
  }
}

With the following

[ConfigurationProperty("remoteOnly", DefaultValue = "false", IsRequired = false)]
public Boolean RemoteOnly { get; set }

not equivalent to the above.

Is this true: do we need to be verbose even with such vanilla properties?

+3
source share
2 answers

Yes, because you rely on an external storage engine (a base class dictionary that finishes populating the configuration file).

, , . , . , , . , , . , , , VS2005 - , ( XML ).

, , " , - ": https://sites.google.com/site/craigandera/craigs-stuff/clr-workings/the-last-configuration-section-handler-i-ll-ever-need

, , .

+5

{ get; set; } ( ). # .

ConfigurationProperty , / , . , , - , /.

, ( ) ?

+2

All Articles