// Hashtable _cacheTable = new Hashtable(); // path --> string value // 获得一个布尔值 // parameters: // strPath 参数路径 // strName 参数名 // bDefault 缺省值 // return: // 所获得的布尔值 public bool GetBoolean(string strPath, string strName, bool bDefault) { #if NO strPath = GetSectionPath(strPath); XmlNode node = dom.SelectSingleNode(strPath); string strText = null; if (node == null) { return(bDefault); } strText = DomUtil.GetAttrOrDefault(node, strName, null); if (strText == null) { return(bDefault); } if (String.Compare(strText, "true", true) == 0) { return(true); } if (String.Compare(strText, "false", true) == 0) { return(false); } return(false); #endif string value = GetString(strPath, strName, null); if (value == null) { return(bDefault); } if (String.Compare(value, "true", true) == 0) { return(true); } if (String.Compare(value, "false", true) == 0) { return(false); } return(false); }
//// // 获得一个浮点数 // parameters: // strPath 参数路径 // strName 参数名 // fDefault 缺省值 // return: // 要获得的字符串 public float GetFloat(string strPath, string strName, float fDefault) { #if NO strPath = GetSectionPath(strPath); XmlNode node = dom.SelectSingleNode(strPath); if (node == null) { return(fDefault); } string strDefault = fDefault.ToString(); string strValue = DomUtil.GetAttrOrDefault(node, strName, strDefault); try { return((float)Convert.ToDouble(strValue)); } catch { return(fDefault); } #endif string value = GetString(strPath, strName, null); if (value == null) { return(fDefault); } try { return((float)Convert.ToDouble(value)); } catch { return(fDefault); } }
// 获得一个整数值 // parameters: // strPath 参数路径 // strName 参数名 // nDefault 缺省值 // return: // 所获得的整数值 public int GetInt(string strPath, string strName, int nDefault) { #if NO strPath = GetSectionPath(strPath); XmlNode node = null; try { node = dom.SelectSingleNode(strPath); } catch (Exception ex) { throw new Exception("strPath 名称 '" + strPath + "' 不合法。应符合 XML 元素命名规则", ex); } string strText = null; if (node == null) { return(nDefault); } strText = DomUtil.GetAttrOrDefault(node, strName, null); if (strText == null) { return(nDefault); } return(Convert.ToInt32(strText)); #endif string value = GetString(strPath, strName, null); if (value == null) { return(nDefault); } return(Convert.ToInt32(value)); }
// 获得一个字符串 // parameters: // strPath 参数路径 // strName 参数名 // strDefalt 缺省值 // return: // 要获得的字符串 public string GetString(string strPath, string strName, string strDefault) { strPath = GetSectionPath(strPath); XmlNode node = null; try { node = dom.SelectSingleNode(strPath); } catch (Exception ex) { throw new Exception("strPath 名称 '" + strPath + "' 不合法。应符合 XML 元素命名规则", ex); } if (node == null) { return(strDefault); } return(DomUtil.GetAttrOrDefault(node, strName, strDefault)); }