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;
}
}
}
}
查看全文
相关阅读:
Java中四种引用类型
使用VisualVM查看Java Heap Dump
Java程序性能分析工具Java VisualVM(Visual GC)—程序员必备利器
JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解
设计模式2---建造者模式(Builder pattern)
设计模式1---单例模式(Singleton pattern)
移动端网络优化
Http请求的 HttpURLConnection 和 HttpClient
第四章 Activity和Activity调用栈分析 系统信息与安全机制 性能优化
Android模块化编程之引用本地的aar
原文地址:https://www.cnblogs.com/haoxiaobo/p/89932.html
最新文章
python colorama模块
pickle模块的基本使用
python lambda表达式用法
开博篇
网络代理
Collections.unmodifiableList()的使用与场景
设计模式9---装饰模式(Decorator Pattern)
OKHttp源码解析
UML简易看懂
设计模式15---观察者模式(Observer Pattern)
热门文章
设计模式11---组合模式(Composite Pattern)
从Java程序员到CTO的成长路线图
设计模式12---享元模式(Flyweight Pattern)
JVM内存模型
设计模式7---Java动态代理机制详解(JDK 和CGLIB,Javassist,ASM)
设计模式6---代理模式(Proxy Pattern)
Java泛型
设计模式4---原型模式(Prototype Pattern)
设计模式5---创建型模式总结
设计模式3---工厂模式(Factory Pattern简单工厂、工厂方法、抽象工厂)
Copyright © 2011-2022 走看看