XElement IActionVisitor <XElement, XElement> .Visit(ActionTry action, XElement param) { var res = new XElement(XActionNames.FromAction(action)); if (action.Reserved != 0) { res.Add(new XAttribute("reserved", action.Reserved)); } if (action.CatchInRegister) { res.Add(new XAttribute("catchReg", action.CatchRegister)); } else { res.Add(new XAttribute("catchName", action.CatchName)); } res.Add(XAction.ToXml(action.Try, new XElement("try"))); if (action.CatchBlock) { res.Add(XAction.ToXml(action.Catch, new XElement("catch"))); } if (action.FinallyBlock) { res.Add(XAction.ToXml(action.Finally, new XElement("finally"))); } return(res); }
XElement IActionVisitor <XElement, XElement> .Visit(ActionDefineFunction action, XElement param) { var res = new XElement(XActionNames.FromAction(action)); res.Add(new XAttribute("name", action.Name), new XAttribute("argc", action.Args.Count) ); var args = new XElement("args"); foreach (var arg in action.Args) { args.Add(new XElement("String", new XAttribute("value", arg))); } res.Add(args); if (action.Actions.Count > 0) { var xActions = new XElement("actions"); foreach (var subaction in action.Actions) { xActions.Add(XAction.ToXml(subaction)); } res.Add(xActions); } return(res); }
ActionBase IActionVisitor <XElement, ActionBase> .Visit(ActionWith action, XElement xAction) { var xActions = xAction.Element("actions"); if (xActions != null) { XAction.FromXml(xActions, action.Actions); } return(action); }
ActionBase IActionVisitor <XElement, ActionBase> .Visit(ActionDefineFunction action, XElement xAction) { var xArgs = xAction.RequiredElement("args"); var xActions = xAction.Element("actions"); action.Name = xAction.RequiredStringAttribute("name"); foreach (var xArg in xArgs.Elements()) { action.Args.Add(xArg.RequiredStringAttribute("value")); } if (xActions != null) { XAction.FromXml(xActions, action.Actions); } return(action); }
ActionBase IActionVisitor <XElement, ActionBase> .Visit(ActionTry action, XElement xAction) { var xReserved = xAction.Attribute("reserved"); var xCatchReg = xAction.Attribute("catchReg"); var xCatchName = xAction.Attribute("catchName"); var xTry = xAction.Element("try"); var xCatch = xAction.Element("catch"); var xFinally = xAction.Element("finally"); if (xReserved != null) { action.Reserved = byte.Parse(xReserved.Value); } if (xCatchReg != null && xCatchName == null) { action.CatchInRegister = true; action.CatchRegister = byte.Parse(xCatchReg.Value); } else if (xCatchReg == null && xCatchName != null) { action.CatchInRegister = false; action.CatchName = xCatchName.Value; } else if (xCatchReg != null && xCatchName != null) { throw new InvalidOperationException("catchReg and catchName are mutally exclusive"); } else { throw new InvalidOperationException("Either catchReg or catchName must be specified"); } XAction.FromXml(xTry, action.Try); if (xCatch != null) { action.CatchBlock = true; XAction.FromXml(xCatch, action.Catch); } if (xFinally != null) { action.FinallyBlock = true; XAction.FromXml(xFinally, action.Finally); } return(action); }