

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

2



3


4

5

6

7

8

9



10

11

12

13



14

15



16

17

18



19

20

21

22

23



24

25

26

27

28


29

30

31

32

33

34



35

36

37

38



39

40



41

42

43

44



45

46

47

48

49

50


51

52

53

54

55

56



57

58

59

60



61

62



63

64

65

66



67

68

69

70

71

72

73


74

75

76

77

78

79



80

81

82

83



84

85



86

87

88

89



90

91

92

93

94

95

96

97
