zoukankan
html css js c++ java
取得程序设定的常用代码.
using
System;
using
System.Configuration;
namespace
HXBTools.Util
{
/**/
///
<summary>
///
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;
}
}
}
}
查看全文
相关阅读:
C++_重载、重写和重定义的区别
C++静态库与动态库
C++ 中重载运算符 “<” 及 friend属性
C++中,关于#include<***.h>和#include"***.h"的区别
static_cast, dynamic_cast, const_cast讨论
浅析C++中static关键字
C语言包含头文件时用引号和尖括号的区别
vc实现透明位图,透明背景
VS2008调试技巧——断点失效
Spring解决循环依赖的理解
原文地址:https://www.cnblogs.com/haoxiaobo/p/89932.html
最新文章
puremvc 调用顺序解读
puremvc 笔记
windows 本地使用git方法
GPU编程与CG语言之阳春白雪下里巴人 读书笔记
shader vs 辅助工具
OPENGL 红宝书实验笔记
CG 标准函数库
shader code 温度云图(温场)实现
0 VS2015 WIN7 配置OPENGL
把本地项目上传到github
热门文章
ubuntu下安装 java环境
linux常用目录
iOS权限申请
数据库相关
photoKit使用笔记
博客搬家一下到CSDN
iOS坐标转换失败?
如何优化增强第三方库?
代码规范
C#中的方括号[](特性、属性)
Copyright © 2011-2022 走看看