Sladescross's Blog

Blogging about Sharepoint related stuff

.NET Custom Configuration Settings December 25, 2009

Filed under: .NET,Configuration,Custom,Settings — sladescross @ 11:53 pm

http://www.codeproject.com/KB/dotnet/mysteriesofconfiguration.aspx

http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx

http://msdn.microsoft.com/en-us/magazine/cc163591.aspx

<configuration>
  <configSections>
    <sectionGroup name=”userSettings”
        type=”System.Configuration.UserSettingsGroup, System,
              Version=2.0.0.0, Culture=neutral,
              PublicKeyToken=b77a5c561934e089″>
      <section name=”MSDNSampleSettings.My.MySettings”
        type=”System.Configuration.ClientSettingsSection, System,
             Version=2.0.0.0, Culture=neutral,
             PublicKeyToken=b77a5c561934e089″
        allowExeDefinition=”MachineToLocalUser”
        requirePermission=”false” />
    </sectionGroup>
  </configSections>
  …
  <userSettings>
    <MSDNSampleSettings.My.MySettings>
      <setting name=”Setting” serializeAs=”String”>
        <value>SomeDefaultValue</value>
      </setting>
    </MSDNSampleSettings.My.MySettings>
  </userSettings>
</configuration>

http://www.nerdymusings.com/LPMArticle.asp?ID=33

A few things in the above code deserve special mention:

  • The CollectionType property specifies AddRemoveClearMap, which is what gives your collection the standard behavior of an element collection in the configuration file.
  • If you specify a key, you’ll need to override GetElementKey to return the value of the appropriate property. Note that your key property doesn’t have to be a string. I could have used my Identifier property as the key.
  • Some of the methods provide a familiar name to access corresponding base class operations. For example, the Clear method executes BaseClear.

http://www.4guysfromrolla.com/articles/032807-1.aspx

About these ads
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 63 other followers