C# Developers' Journal (original) (raw)

1:58p

Using a custom (XML) configuration section I had a need recently to build a custom configuration file reader so we could use an XML based config file to populate date to our batch emailing program. The Key/Value pairing functionality of the Standard AppSettings wouldn't work, as we had several email profiles to mail to.

Here is the code to build a custom config handler (extends IConfigurationSectionHandler)
This code needs to be in a class by itself, as the Configuration handler sees the entry in the config file for the custom handler (

)
And searches for a DLL in the path (I keep it in the application directory) of the same name.
This code can read application.exe.config files, web.config, machine.config etc.

( CodeCollapse )

the type class is populated and put into an object array (hashtable in this case, the hashtable is retrieved by the application in need of the data at runtime:
( Integration CodeCollapse )

and finally a few changes to the config file to add this data in it:

( config fileCollapse )