2014/08/22

How to read config section from configuration file in C# ?

App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="GateInvocationMax" value="10"/>
</appSettings>
</configuration>
view raw gistfile1.cs hosted with ❤ by GitHub
Class that reads config file.
Remember to add System.Configuration to Project references !
using System.Configuration;
namespace Interlook.Common
{
public class ConfigManager
{
public static int GateInvocationMax
{
get
{
int gateInvocationMax = 10;
int.TryParse(ConfigurationManager.AppSettings["GateInvocationMax"], out gateInvocationMax);
return gateInvocationMax;
}
}
}
}
view raw gistfile1.cs hosted with ❤ by GitHub

No comments:

Post a Comment