CustomerConfigHelper
public static class CustomerConfigHelper
{
public static object _lockObject = new object();
private static string GetCustomConfigValue(string key)
{
string configFilePath = "~/Config/CustomConfig.config";
string configElementsName = "Add";
string configAttributeKeyName = "Key";
string configAttributeValueName = "Value";
return GetValue(key,configFilePath, configElementsName, configAttributeKeyName,configAttributeValueName);
}
private static string GetValue(string key,string configFilePath)
{
string configElementsName = "Add";
string configAttributeKeyName = "Key";
string configAttributeValueName = "Value";
return GetValue(key,configFilePath, configElementsName, configAttributeKeyName,configAttributeValueName);
}
private static string GetValue(string key, string configFilePath, string configElementsName, string configAttributeKeyName,string configAttributeValueName)
{
string _value = string.Empty;
string _path = HttpContext.Current.Server.MapPath(configFilePath);
XElement _element = XElement.Load(_path);
var _config = from config in _element.Elements(configElementsName) select config;
Dictionary<string, string> _dic = _config.ToDictionary(k => k.Attribute(configAttributeKeyName).Value, k => k.Attribute(configAttributeValueName).Value);
_dic.TryGetValue(key, out _value);
return _value;
}
/// <summary>
/// 获取自定义文件配置节点值:整形
/// </summary>
/// <param name="key">配置节点KEY</param>
/// <returns></returns>
public static int GetCustomConfigInt(string key)
{
return TypeHelper.ToInt(GetCustomConfigValue(key));
}
/// <summary>
/// 获取自定义文件配置节点值:整形
/// </summary>
/// <param name="key"></param>
/// <param name="configFilePath"></param>
/// <returns></returns>
public static int GetCustomConfigInt(string key, string configFilePath)
{
return TypeHelper.ToInt(GetValue(key, configFilePath));
}
/// <summary>
/// 获取自定义文件配置节点值:长整形
/// </summary>
/// <param name="key">配置节点KEY</param>
/// <returns></returns>
public static long GetCustomConfigLong(string key)
{
return TypeHelper.ToInt64(GetCustomConfigValue(key));
}
/// <summary>
/// 获取自定义文件配置节点值:长整形
/// </summary>
/// <param name="key"></param>
/// <param name="configFilePath"></param>
/// <returns></returns>
public static long GetCustomConfigLong(string key, string configFilePath)
{
return TypeHelper.ToInt64(GetValue(key, configFilePath));
}
/// <summary>
/// 获取自定义文件配置节点值:字符串
/// </summary>
/// <param name="key">配置节点KEY</param>
/// <returns></returns>
public static string GetCustomConfigString(string key)
{
return GetCustomConfigValue(key);
}
/// <summary>
/// 获取自定义文件配置节点值:字符串
/// </summary>
/// <param name="key"></param>
/// <param name="configFilePath"></param>
/// <returns></returns>
public static string GetCustomConfigString(string key, string configFilePath)
{
return GetValue(key, configFilePath);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<customconfig>
<!--分页页码大小-->
<Add Key="PageSize" Value="10"></Add>
<!--图片路径-->
<Add Key="ImagesWebPath" Value="http://xxx.xx.xxx.xxx:9000"></Add>
</customconfig>
最新文章
- CSS3使用Font Awesome字体图标的控件样例(按钮,工具栏,输入框)
- 第14章 集合框架(1)-List集合的各种类
- pure virtual function call
- 设计模型MVC和JavaBean
- java 附件上传时后台验证上传文件的合法性
- angularJS常见问题汇总
- Google Play市场考察报告
- 深入理解Python中的生成器
- Jenkins学习之——(4)Email Extension Plugin插件的配置与使用
- actionBar兼容2.1及以上版本的做法 .
- Android应用开发学习之AlertDialog对话框
- B - Numbers That Count
- ImportError: No module named _sqlite3 - 代码分享
- getch()、getche()和getchar()函数
- android获取存储卡使用情况
- P4语言编程快速开始 实践一
- Python生产环境部署(fastcgi,uwsgi)
- 【Linux】查看系统位数
- python模块------shutil
- env:bash \r解决
热门文章
- 如何在.net4.0中使用.net4.5的async/await
- Ubuntu优化-py用机器
- INADDR_ANY的确切含义
- 20135306黄韧 附录A及第十章学习总结
- wen7安装oracle 11g出现";未找到文件 E:\development_tools\database\oracle\install_d\dbhome\owb\external\oc4j_applications\applications\WFMLRSVCApp.ear";
- 20145215《Java程序设计》第2周学习总结
- jdbc基础 (二) 通过properties配置文件连接数据库
- 打造自己的MyLifeOrganized 2(MLO2)云同步
- Could not open Hibernate Session for transaction;
- xml文件的读写操作