private void ParseOption(List <AdminOption> options, string data) { string[] tokens = data.Split(new char[] { '|', ',' }); foreach (var option in tokens) { int pos = option.IndexOf(':'); if (pos == -1) { continue; } AdminOption op = new AdminOption(); op.Name = option.Substring(0, pos).Trim(); op.Data = option.Substring(pos + 1).Trim(); options.Add(op); } }
private void ReadOption(XmlElement node) { AdminOptionList optionList = new AdminOptionList(); optionList.Name = node.GetAttribute("name"); // 简易书写,通过格式 string options = node.GetAttribute("value"); if (!string.IsNullOrEmpty(options)) { ParseOption(optionList.Options, options); } XmlNodeList param_nodes = node.GetElementsByTagName("option"); foreach (var param in param_nodes) { XmlElement elem = (XmlElement)param; AdminOption option = new AdminOption(); if (elem.HasAttribute("data")) {// 两种方式解析 string data = elem.GetAttribute("data"); string[] tokens = data.Split(':'); if (tokens.Length != 2) { throw new Exception("bad option format!!"); } option.Name = tokens[0].Trim(); option.Data = tokens[1].Trim(); } else { option.Name = elem.GetAttribute("key").Trim(); option.Data = elem.GetAttribute("value").Trim(); } optionList.Options.Add(option); } OptionMap.Add(optionList.Name, optionList); }
private void ParseOption(List<AdminOption> options, string data) { string[] tokens = data.Split(new char[] { '|', ',' }); foreach (var option in tokens) { int pos = option.IndexOf(':'); if (pos == -1) continue; AdminOption op = new AdminOption(); op.Name = option.Substring(0, pos).Trim(); op.Data = option.Substring(pos + 1).Trim(); options.Add(op); } }
private void ReadOption(XmlElement node) { AdminOptionList optionList = new AdminOptionList(); optionList.Name = node.GetAttribute("name"); // 简易书写,通过格式 string options = node.GetAttribute("value"); if(!string.IsNullOrEmpty(options)) { ParseOption(optionList.Options, options); } XmlNodeList param_nodes = node.GetElementsByTagName("option"); foreach(var param in param_nodes) { XmlElement elem = (XmlElement)param; AdminOption option = new AdminOption(); if (elem.HasAttribute("data")) {// 两种方式解析 string data = elem.GetAttribute("data"); string[] tokens = data.Split(':'); if (tokens.Length != 2) throw new Exception("bad option format!!"); option.Name = tokens[0].Trim(); option.Data = tokens[1].Trim(); } else { option.Name = elem.GetAttribute("key").Trim(); option.Data = elem.GetAttribute("value").Trim(); } optionList.Options.Add(option); } OptionMap.Add(optionList.Name, optionList); }