public static List <CmdName> LoadFlowtest(string filePath) { XDocument doc = XDocument.Load(filePath); XElement rootMain = doc.Element("CmdPackage"); //新建和命令个数匹配的类 //int count_cmd = rootMain.Elements("Cmd").Count(); //CmdName[] cmd = new CmdName[count_cmd]; List <CmdName> cmdList = new List <CmdName>(); List <Action_> actList = new List <Action_>(); int i = 0; foreach (XElement node in rootMain.Elements("Cmd")) { CmdName cmd_name = new CmdName(); //取出 loop cmd_name.Loop = node.Attribute("Loop").Value; //取出 name string name = node.Attribute("name").Value; cmd_name.Name = node.Attribute("name").Value; int count_act = node.Elements("action").Count(); int j = 0; foreach (var item in node.Elements("action")) { Action_ act = new Action_(); //取出name action act.Name = item.Attribute("name").Value; act.Res = item.Attribute("Res").Value; actList.Add(act); cmd_name.action = actList; j++; } cmdList.Add(cmd_name); i++; } return(cmdList); }
public static List <CmdName> ReadAttribute(string filePath) { XDocument doc = XDocument.Load(filePath); XElement rootMain = doc.Element("CmdPackage"); List <CmdName> cmdList = new List <CmdName>(); List <Before> Before = new List <Before>(); List <After> After = new List <After>(); foreach (XElement node in rootMain.Elements("Cmd")) { CmdName cmd_name = new CmdName(); //取出 loop cmd_name.Loop = node.Attribute("Loop").Value; cmd_name.Name = node.Attribute("name").Value; foreach (var item in node.Elements("Before")) { Before before = new Before(); before.Action = item.Attribute("action").Value; before.Res = item.Attribute("Res").Value; Before.Add(before); cmd_name.before = Before; } foreach (var item in node.Elements("After")) { After after = new After(); //取出name action after.Action = item.Attribute("action").Value; after.Res = item.Attribute("Res").Value; After.Add(after); cmd_name.after = After; } cmdList.Add(cmd_name); } return(cmdList); }