using System;
using System.Configuration;

namespace HXBTools.Util
{
![]()
/// Class1 的摘要说明。
/// </summary>
public class Config
{
public Config()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public static string GetSettingString(string sKeyName, string sDefault)
{
string s = ConfigurationSettings.AppSettings[sKeyName];
if (s == null)
{
return sDefault;
}
else
{
return s;
}
}

public static int GetSettingInt(string sKeyName, int iDefault)
{
string s = Config.GetSettingString(sKeyName, null);
if (s == null)
return iDefault;

int i;
try
{
i = int.Parse(s);
return i;
}
catch
{
return iDefault;
}

}


public static long GetSettingLong(string sKeyName, long lDefault)
{
string s = Config.GetSettingString(sKeyName, null);
if (s == null)
return lDefault;

long l;
try
{
l = long.Parse(s);
return l;
}
catch
{
return lDefault;
}

}


public static decimal GetSettingDecimal(string sKeyName, decimal dcDefault)
{
string s = Config.GetSettingString(sKeyName, null);
if (s == null)
return dcDefault;

decimal dc;
try
{
dc = decimal.Parse(s);
return dc;
}
catch
{
return dcDefault;
}

}

public static DateTime GetSettingDateTime(string sKeyName, DateTime dtDefaule)
{
string s = Config.GetSettingString(sKeyName, null);
if (s == null)
return dtDefaule;

DateTime dt;
try
{
dt = DateTime.Parse(s);
return dt;
}
catch
{
return dtDefaule;
}

}

public static bool GetSettingBool(string sKeyName, bool bDefault)
{
string s = Config.GetSettingString(sKeyName, null);
if (s == null)
return bDefault;
switch(s.Trim().ToLower())
{
case "true":
case "真":
case "是":
case "1":
case "yes":
case "ok":
case "-1":
return true;
case "false":
case "0":
case "假":
case "否":
case "不":
case "非":
case "no":
case "not":
case "never":
return false;
default:
return bDefault;
}
}
}
}
相关文章:
-
2021-05-19
-
2021-05-16
-
2021-05-25
-
2022-12-23
-
2021-08-30
-
2021-07-01
-
2021-10-21
猜你喜欢
-
2022-03-03
-
2022-12-23
-
2021-05-22
-
2021-06-01
-
2021-07-13
-
2021-10-04
-
2022-12-23
相关资源
-
下载
2023-03-07
-
下载
2023-01-07
-
下载
2023-01-21
-
下载
2021-06-24