public static XmlNode ToXMLNode(XmlNode parent, XMLConfig config) { XmlNode root = XMLUtil.AddChildNode(parent, config.name, ""); foreach (string key in config.attrDict.Keys) { if (key == Config_Path_Key) { continue; } string value = config.attrDict[key]; XMLUtil.SetNodeAttrValue(root, key, value); } foreach (string key in config.propDict.Keys) { string value = config.propDict[key]; XmlNode child = XMLUtil.AddChildNode(root, Property_Key, ""); XMLUtil.SetNodeAttrValue(child, Name_Key, key); if (value.Length < 100 && value.IndexOf('\n') == -1 && value.IndexOf('\r') == -1) { XMLUtil.SetNodeAttrValue(child, Value_Key, value); } else { XMLUtil.SetNodeValue(child, value); } } for (int i = 0; i < config.configList.Count; i++) { ToXMLNode(root, (XMLConfig)config.configList[i]); } return(root); }
public XMLConfig RemoveConfig(int index) { XMLConfig config = this.configList[index]; this.configList.RemoveAt(index); return(config); }
public XMLConfig AddConfig(int index, string tag) { XMLConfig subConfig = new XMLConfig(); subConfig.parentConfig = this; subConfig.SetName(tag); this.configList.Insert(index, subConfig); return(subConfig); }
public XMLConfig AddConfig(string tag) { XMLConfig subConfig = new XMLConfig(); subConfig.parentConfig = this; subConfig.SetName(tag); this.configList.Add(subConfig); return(subConfig); }
public XMLConfig removeConfig(string attrName, string attrValue) { XMLConfig config = GetConfig(attrName, attrValue); if (config != null) { this.configList.Remove(config); } return(config); }
public XMLConfig RemoveConfig(string tag) { XMLConfig config = GetConfig(tag); if (config != null) { this.configList.Remove(config); } return(config); }
public XMLConfig GetConfig(string tag) { for (int i = 0; i < this.configList.Count; i++) { XMLConfig config = (XMLConfig)this.configList[i]; if (tag == config.GetName()) { return(config); } } return(null); }
public XMLConfig GetConfig(string attrName, string attrValue) { for (int i = 0; i < GetConfigCount(); i++) { XMLConfig config = (XMLConfig)this.configList[i]; if (config.GetAttribute(attrName) == attrValue) { return(config); } } return(null); }
public bool HasConfig(string tag) { for (int i = 0; i < this.configList.Count; i++) { XMLConfig conf = (XMLConfig)this.configList[i]; if (tag == conf.GetName()) { return(true); } } return(false); }
public void Reload() { if (Reloadable()) { this.configList.Clear(); this.propDict.Clear(); this.attrDict.Clear(); this.parentConfig = null; this.name = null; LoadFrom(this.configFile); return; } throw new IOException("无法重新载入配置信息"); }
public XMLConfig[] GetConfigs(string tag) { List <XMLConfig> configList = new List <XMLConfig>(); for (int i = 0; i < this.configList.Count; i++) { XMLConfig config = (XMLConfig)this.configList[i]; if (tag == config.GetName()) { configList.Add(config); } } XMLConfig[] configs = new XMLConfig[configList.Count]; configs = configList.ToArray(); return(configs); }
public XMLConfig MatchesConfig(string attrName, string attrValue) { Regex r = new Regex(attrValue, RegexOptions.IgnoreCase); for (int i = 0; i < GetConfigCount(); i++) { XMLConfig config = (XMLConfig)this.configList[i]; if (config.HasAttribute(attrName)) { Match m = r.Match(config.GetAttribute(attrName)); if (m.Success) { return(config); } } } return(null); }
public void AddConfig(int index, XMLConfig subConfig) { subConfig.parentConfig = this; this.configList.Insert(index, subConfig); }
public void AddConfig(XMLConfig subConfig) { subConfig.parentConfig = this; this.configList.Add(subConfig); }
public XMLConfig[] GetConfigs() { XMLConfig[] configs = new XMLConfig[this.configList.Count]; configs = this.configList.ToArray(); return(configs); }
public void LoadFrom(XmlNode node) { if (this.name == null) { string name = node.Name; if (name != null) { this.name = name.Trim(); } } Dictionary <string, string> nodeAttrDict = XMLUtil.GetNodeAttrs(node); foreach (string key in nodeAttrDict.Keys) { if (this.attrDict.ContainsKey(key)) { continue; } string value = nodeAttrDict.GetOrAddDefault(key, () => ""); this.attrDict[key] = value; } XmlNode child = node.FirstChild; XMLConfig subConfig = null; while (child != null) { if (child.NodeType == XmlNodeType.Element) { if (IsPropertyNode(child)) { LoadProperty(child); } else { string childNodeName = child.Name; if (childNodeName == null) { continue; } childNodeName = childNodeName.Trim(); string parseClassString = XMLUtil.GetNodeAttrValue(child, "parseClass", ""); if (parseClassString.Length > 0) { subConfig = (XMLConfig)Activator.CreateInstance(Type.GetType(parseClassString)); } else { subConfig = new XMLConfig(); } subConfig.parentConfig = this; subConfig.name = childNodeName; subConfig.LoadFrom(child); // 不断循环下一层 this.configList.Add(subConfig); } } child = child.NextSibling; } string configPath = nodeAttrDict.GetOrAddDefault(Config_Path_Key, () => ""); if (configPath.Length > 0) { LoadFrom(configPath); } }