In our day-to-day development, rarely, we don’t need to read a configuration file. There are many techniques for the treatment of such static classes, singleton classes, etc. and, normally, the Config class is accessible in all projects.
We write a utility to automate the reading of app.config files. With this utility, you will forget the ConfigurationManager class and the System.Configuration assembly.
We will support each of them for this dynamically.
App.Config Autoreader is an open-source project and is available in the MoralesLarios.Development project on GitHub. Here is the link.
Index
- Autoreader description
- Install and use
- Pros and Cons
- Autoreader Transforms Types
- Strings values
- Numerics values
- Date and DateTime values
- Bools values
- Arrays values
- Force values to string
- Save special character
Autoreader description
The Autoreader action is used for reading app.config file in the first step, converting values action in the second step, and creating a result class in the final step,

A simple example of a string value.

The process transforms the string key value to a strongly typed target variable. The Config class is responsible for exposing the transformed app.config values. The Config class exposes the app.Config values with strong types, but in a dynamic property.
Installation and use
- To use it, we need to download a NuGet Package.

- Install-Package MoralesLarios.Development

- Add the following setting in the app.config file.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> <appSettings> <add key="FilterDate" value="01/01/2018" /> </appSettings> </configuration> - Add using in the consumer class.
using MoralesLarios.Development.Configuration; - Create a new variable of your app.config settings key and call Config.ConfigNodes.[app.config_keyName].
static void Main(string[] args) { DateTime filterDate = Config.ConfigNodes.FilterDate; } - All code
using MoralesLarios.Development.Configuration; using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { DateTime filterDate = Config.ConfigNodes.FilterDate; } } }
The execution reads a DateTime value.















Join the conversation! Your thoughts help the community grow.