Skip to content
AppSettings class mapper
C# Batchfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

AppSettingsMapper library v.0.3.1

The AppSettingsMapper library used for map App.config appSettings section items to custom C# class. Library allows to map all property types such as int, short, double, TimeSpan, DateTime etc. Also you can map on custom property types of C# class.


For example you have App.config file like this:

<?xml version="1.0" encoding="utf-8" ?>
    <add name="SqlExpressConnection" connectionString="Data Source=localhost\SqlExpress; Initial catalog=Test;" />
    <add key="ShowTooltip" value="true" />
    <add key="TemplatesFolder" value="Templates/" />
    <add key="LockDuration" value="1:30:00" />
    <add key="IsCompiled" value="true" />
    <add key="RequiredKey" value="123" />
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

and you have a settings class AttributesExampleSettings.cs:

class AttributesExampleSettings
	public ConnectionStringSettings SqlExpressConnection { get; set; }

	public bool ShowTooltip { get; set; }

	public string TemplatesFolder { get; set; }

	public TimeSpan LockDuration { get; set; }
	public bool A { get; set; }

	public int RequiredKey { get; set; }

	public string User { get; set; }

	public int IgnoredValue { get; set; }

	public AttributesExampleSettings()
		IgnoredValue = 1234;

than you can use AppSettingsMapper for map appSettings section to AttributesExampleSettings class:

var settings = AppSettings.MapTo<AttributesExampleSettings>();

// settings.SqlExpressConnection.Name = "SqlExpressConnection"
// settings.SqlExpressConnection.ConnectionString = "Data Source=localhost\SqlExpress; Initial catalog=Test;"
// settings.ShowTooltip = true;
// settings.TemplatesFolder = "Templates/";
// settings.LockDuration = new TimeStamp(1, 30, 0);
// settings.A = true; // Value from IsCompiled setting.
// settings.RequiredKey = 123;
// settings.User = "admin";
// settings.IgnoredValue = 1234;

To install:

Run the following command in the Package Manager Console to install:

Install-Package AppSettingsMapper


Skype: dimaermakov


You can’t perform that action at this time.