Creating a custom configuration section in .NET
How to create a custom type for app.config and web.config in .NET
We are creating a configuration for a crazy cat lady.
Reference System.Configuration in your project.
This contains many of the classes and attributes we will be using.
Create a class to represent individual cats, one to represent a collection of cats, and finally one for the lady.
The ConfigurationElement class
Represents a configuration element within a configuration file.
We can define attributes and children by using the ConfigurationProperty attribute on member properties. Here we define a cat type with three attribute properties: name, color, and age. We demonstrate some of the features of ConfigurationPropertyAttribute, marking the latter two as optional, and giving age a default. CatConfiguration.cs using System.Configuration;
namespace CatLadyDemo
{
public classCatConfiguration : ConfigurationElement
{
private const string NameKey = "name";
private …
We can define attributes and children by using the ConfigurationProperty attribute on member properties. Here we define a cat type with three attribute properties: name, color, and age. We demonstrate some of the features of ConfigurationPropertyAttribute, marking the latter two as optional, and giving age a default. CatConfiguration.cs using System.Configuration;
namespace CatLadyDemo
{
public classCatConfiguration : ConfigurationElement
{
private const string NameKey = "name";
private …