首页 > 代码库 > KeyValue Config
KeyValue Config
public class ConfigHelper { public static ScriptsHelper Scripts { get { return new ScriptsHelper(); } } public static ParametersHelper Parameters { get { return new ParametersHelper(); } } } public class ScriptsHelper { string fileName = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"Scripts.xml"); public PerScript this[string name] { get { string value = http://www.mamicode.com/Tools.ExecuteXPathInFile(fileName, string.Format(@"/Scripts/Script[@name=‘{0}‘]/text()", name.Trim())); string connection = Tools.ExecuteXPathInFile(fileName, string.Format(@"/Scripts/Script[@name=‘{0}‘]/@connectionName", name.Trim())); PerScript script = new PerScript(value, connection); return script; } } public class PerScript { public PerScript(string value, string connection) { m_Value = http://www.mamicode.com/value;"/KeyValues/KeyValue[@name=‘{0}‘]", name.Trim())); if (keyValueStr != null) { PerKeyValue returnObj = new PerKeyValue(name, keyValueStr); return returnObj; } else { return null; } } } public class PerKeyValue { public PerKeyValue(string name, string keyValueStr) { m_KeyValueStr = keyValueStr; m_Name = name; m_Value = http://www.mamicode.com/Tools.ExecuteXPathInString(keyValueStr, @"/KeyValue/text()"); } string m_KeyValueStr; private string m_Name; public string Name { get { return m_Name; } } public PerKeyValueAttributes Attributes { get { string[] temp = m_KeyValueStr.GetSubString(@"(?<=\<KeyValue\s+).+.(?=/?\>)"); if (temp != null && temp.Length > 0) return new PerKeyValueAttributes(temp[0]); else return null; } } string m_Value; public string Value { get { return m_Value; } } public List<PerKeyValue> KeyValus { get { List<PerKeyValue> list = null; XmlDocument doc = new XmlDocument(); doc.LoadXml(m_KeyValueStr); XmlNodeList nodes = doc.SelectNodes("/KeyValue/KeyValue"); if (nodes != null && nodes.Count > 0) { list = new List<PerKeyValue>(); foreach (XmlNode item in nodes) { list.Add(new PerKeyValue(item.Attributes["name"].InnerText, item.OuterXml)); } } return list; } } public PerKeyValue this[string name] { get { string keyValueStr = Tools.ExecuteXPathInString(m_KeyValueStr, string.Format(@"/KeyValue/KeyValue[@name=‘{0}‘]", name.Trim())); if (keyValueStr != null) return new PerKeyValue(name, keyValueStr); else return null; } } } public class PerKeyValueAttributes { public PerKeyValueAttributes(string attributes) { m_Attributes = attributes; } string m_Attributes = string.Empty; public string this[string name] { get { string[] results = m_Attributes.GetSubString(string.Format(@"(?<={0}\s*="").+", name)); if (results != null && results.Length > 0) { return results[0].ReplaceString(@""".*", string.Empty); } else return null; } } } }
KeyValue Config
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。