using HighWayIot.Repository.service; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace HighWayIot.Winform.Business { /// /// XML读写类 /// public class XmlUtil { private static readonly Lazy lazy = new Lazy(() => new XmlUtil()); public static XmlUtil Instance { get { return lazy.Value; } } /// /// XML读写实例 /// XmlDocument xmlDocument = new XmlDocument(); /// /// 运行时路径 /// private string Path = System.Environment.CurrentDirectory; public List ConfigReader() { List list = new List(); xmlDocument.Load($"{Path}\\Configuration.xml"); XmlNode root = xmlDocument.DocumentElement; XmlNode node = root.SelectSingleNode("RoleConfig"); foreach (XmlNode role in node) { XmlAttribute pageName = (XmlAttribute)role.Attributes.GetNamedItem("PageName"); XmlAttribute roleIndex = (XmlAttribute)role.Attributes.GetNamedItem("RoleIndex"); int.TryParse(roleIndex.Value, out int index); list.Add(new RoleConfig() { PageName = pageName.Value, RoleIndex = index, }); } return list; } } public class RoleConfig { /// /// 页面名称 /// public string PageName { get; set; } /// /// 规则编号 /// public int RoleIndex { get; set; } } }