Showing posts with label Settings. Show all posts
Showing posts with label Settings. Show all posts

November 1, 2012

Settings in .NET are easy

As I said 'few' days ago, today I`ll tell you about Settings files.
Settings files are designed to make our life simpler during working with application and user configuration.

A bit theory

Settings file consists of few parts in our project.
  1. Settings file (auto generated class derived from ApplicationSettingsBase).
  2. app.config (contains default values for all options).
Generated setting file derived from ApplcationSettingsBase already contains initialized static instances of all our options. We don't need to create this class manually and load any data, because it has already been created and loaded. And it is ready to work.

All settings have next properties:
  • Name (this is the name of our setting): with this name we will have automatically generated property in Settings class.
  • Type (the type of our setting): there are a lot of predefined types like string, int, etc., but you can also set your custom type.
  • Value (this is default value for setting).
  • Scope: all settings should be in one of two scopes (User or Application). It represents how our setting will be accessed at runtime.