
代码 1
public sealed class ConfigHelper
2
{
3
/**//// <summary>
4
/// 得到AppSettings中的配置字符串信息
5
/// </summary>
6
/// <param name="key"></param>
7
/// <returns></returns>
8
public static string GetConfigString(string key)
9
{
10
string CacheKey = "AppSettings-" + key;
11
object objModel = LTP.Common.DataCache.GetCache(CacheKey);
12
if (objModel == null)
13
{
14
try
15
{
16
objModel = ConfigurationManager.AppSettings[key];
17
if (objModel != null)
18
{
19
LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(180), TimeSpan.Zero);
20
}
21
}
22
catch
23
{ }
24
}
25
return objModel.ToString();
26
}
27
28
/**//// <summary>
29
/// 得到AppSettings中的配置Bool信息
30
/// </summary>
31
/// <param name="key"></param>
32
/// <returns></returns>
33
public static bool GetConfigBool(string key)
34
{
35
bool result = false;
36
string cfgVal = GetConfigString(key);
37
if(null != cfgVal && string.Empty != cfgVal)
38
{
39
try
40
{
41
result = bool.Parse(cfgVal);
42
}
43
catch(FormatException)
44
{
45
// Ignore format exceptions.
46
}
47
}
48
return result;
49
}
50
/**//// <summary>
51
/// 得到AppSettings中的配置Decimal信息
52
/// </summary>
53
/// <param name="key"></param>
54
/// <returns></returns>
55
public static decimal GetConfigDecimal(string key)
56
{
57
decimal result = 0;
58
string cfgVal = GetConfigString(key);
59
if(null != cfgVal && string.Empty != cfgVal)
60
{
61
try
62
{
63
result = decimal.Parse(cfgVal);
64
}
65
catch(FormatException)
66
{
67
// Ignore format exceptions.
68
}
69
}
70
71
return result;
72
}
73
/**//// <summary>
74
/// 得到AppSettings中的配置int信息
75
/// </summary>
76
/// <param name="key"></param>
77
/// <returns></returns>
78
public static int GetConfigInt(string key)
79
{
80
int result = 0;
81
string cfgVal = GetConfigString(key);
82
if(null != cfgVal && string.Empty != cfgVal)
83
{
84
try
85
{
86
result = int.Parse(cfgVal);
87
}
88
catch(FormatException)
89
{
90
// Ignore format exceptions.
91
}
92
}
93
94
return result;
95
}
96
}
97
public sealed class ConfigHelper2

{3

/**//// <summary>4
/// 得到AppSettings中的配置字符串信息5
/// </summary>6
/// <param name="key"></param>7
/// <returns></returns>8
public static string GetConfigString(string key)9

{10
string CacheKey = "AppSettings-" + key;11
object objModel = LTP.Common.DataCache.GetCache(CacheKey);12
if (objModel == null)13

{14
try15

{16
objModel = ConfigurationManager.AppSettings[key];17
if (objModel != null)18

{ 19
LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(180), TimeSpan.Zero);20
}21
}22
catch23

{ }24
}25
return objModel.ToString();26
}27

28

/**//// <summary>29
/// 得到AppSettings中的配置Bool信息30
/// </summary>31
/// <param name="key"></param>32
/// <returns></returns>33
public static bool GetConfigBool(string key)34

{35
bool result = false;36
string cfgVal = GetConfigString(key);37
if(null != cfgVal && string.Empty != cfgVal)38

{39
try40

{41
result = bool.Parse(cfgVal);42
}43
catch(FormatException)44

{45
// Ignore format exceptions.46
}47
}48
return result;49
}50

/**//// <summary>51
/// 得到AppSettings中的配置Decimal信息52
/// </summary>53
/// <param name="key"></param>54
/// <returns></returns>55
public static decimal GetConfigDecimal(string key)56

{57
decimal result = 0;58
string cfgVal = GetConfigString(key);59
if(null != cfgVal && string.Empty != cfgVal)60

{61
try62

{63
result = decimal.Parse(cfgVal);64
}65
catch(FormatException)66

{67
// Ignore format exceptions.68
}69
}70

71
return result;72
}73

/**//// <summary>74
/// 得到AppSettings中的配置int信息75
/// </summary>76
/// <param name="key"></param>77
/// <returns></returns>78
public static int GetConfigInt(string key)79

{80
int result = 0;81
string cfgVal = GetConfigString(key);82
if(null != cfgVal && string.Empty != cfgVal)83

{84
try85

{86
result = int.Parse(cfgVal);87
}88
catch(FormatException)89

{90
// Ignore format exceptions.91
}92
}93

94
return result;95
}96
}97
