public static LuaFunctionInfo ConvertRoot(XRoot root) { bool isFunction = false; var info = new LuaFunctionInfo(); foreach (var template in root.Templates) { var translated = TranslateTemplate.Translate(template); if (translated is FuncTemplate func) { isFunction = true; info.Description = func.Description; } else if (translated is ArgTemplate arg) { var argumentDeclaration = new IDescribeArgument { Name = arg.Name, Type = TranslateType(arg.Type), Description = arg.Desc }; if (!string.IsNullOrWhiteSpace(arg.Default)) { argumentDeclaration.Attributes.Add(new CodeAttributeDeclaration(nameof(OptionalAttribute))); } info.Arguments.Add(argumentDeclaration); } else if (translated is RetTemplate ret) { info.Returns.Add(new IDescribeReturn { Type = TranslateType(ret.Type), Description = ret.Desc }); } else if (translated is ExampleTemplate example) { info.Examples.Add(example); } } if (!isFunction) { return(null); } return(info); }
public static XRoot ParseXML(string rawxml) { var xml = new XmlDocument(); xml.LoadXml(rawxml); var root = new XRoot(); foreach (XmlNode XTemplate in xml.ChildNodes[0].ChildNodes) { if (XTemplate.Name != "template") { continue; } if (XTemplate.ChildNodes.Count > 0) { var template = new XTemplate(); foreach (XmlNode child in XTemplate.ChildNodes) { if (child.Name == "title") { template.Title = child.InnerText; } else if (child.Name == "part") { var part = new XPart { Name = child.FirstChild.InnerText, // sorry Value = child.LastChild.InnerText }; template.Parts.Add(part); } } root.Templates.Add(template); } } return(root); }