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>

最新文章

  1. CSS3使用Font Awesome字体图标的控件样例(按钮,工具栏,输入框)
  2. 第14章 集合框架(1)-List集合的各种类
  3. pure virtual function call
  4. 设计模型MVC和JavaBean
  5. java 附件上传时后台验证上传文件的合法性
  6. angularJS常见问题汇总
  7. Google Play市场考察报告
  8. 深入理解Python中的生成器
  9. Jenkins学习之——(4)Email Extension Plugin插件的配置与使用
  10. actionBar兼容2.1及以上版本的做法 .
  11. Android应用开发学习之AlertDialog对话框
  12. B - Numbers That Count
  13. ImportError: No module named _sqlite3 - 代码分享
  14. getch()、getche()和getchar()函数
  15. android获取存储卡使用情况
  16. P4语言编程快速开始 实践一
  17. Python生产环境部署(fastcgi,uwsgi)
  18. 【Linux】查看系统位数
  19. python模块------shutil
  20. env:bash \r解决

热门文章

  1. 如何在.net4.0中使用.net4.5的async/await
  2. Ubuntu优化-py用机器
  3. INADDR_ANY的确切含义
  4. 20135306黄韧 附录A及第十章学习总结
  5. wen7安装oracle 11g出现&quot;未找到文件 E:\development_tools\database\oracle\install_d\dbhome\owb\external\oc4j_applications\applications\WFMLRSVCApp.ear&quot;
  6. 20145215《Java程序设计》第2周学习总结
  7. jdbc基础 (二) 通过properties配置文件连接数据库
  8. 打造自己的MyLifeOrganized 2(MLO2)云同步
  9. Could not open Hibernate Session for transaction;
  10. xml文件的读写操作