public Method(IReadOnlyItem elem, bool isCore = false) { FillItemRef(this, elem, false); this.KeyedName = elem.Property("name").AsString(""); this.IsCore = elem.Property("core").AsBoolean(isCore); this.Documentation = AmlDocumentation.Parse(this.KeyedName, elem.Property("method_code").AsString("")); this.Documentation.Summary = this.Documentation.Summary ?? elem.Property("comments").AsString(null); }
public AmlDocumentation GetOrAddAttribute(string name) { _attributes = _attributes ?? new List <AmlDocumentation>(); var attr = _attributes.FirstOrDefault(d => d.Name == name); if (attr == null) { attr = new AmlDocumentation() { Name = name }; _attributes.Add(attr); } return(attr); }
public AmlDocumentation GetOrAddElement(string name) { _elements = _elements ?? new List <AmlDocumentation>(); var element = _elements.FirstOrDefault(d => d.Name == name); if (element == null) { element = new AmlDocumentation() { Name = name }; _elements.Add(element); } return(element); }
public static AmlDocumentation Parse(string methodName, string methodCode) { var method = new AmlDocumentation { Name = methodName }; if (string.IsNullOrEmpty(methodCode)) { return(method); } var lines = methodCode .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var xmlComments = new StringBuilder(); var language = Language.Unknown; for (var i = 0; i < lines.Length; i++) { var trimmed = lines[i].TrimStart(); if (trimmed.StartsWith("///") || trimmed.StartsWith("'''")) { if (language == Language.Unknown) { language = trimmed.StartsWith("///") ? Language.Csharp : Language.Vb; } else if (language == Language.Csharp && !trimmed.StartsWith("///")) { break; } else if (language == Language.Vb && !trimmed.StartsWith("'''")) { break; } xmlComments.AppendLine(trimmed.Substring(3)); } else { break; } } if (xmlComments.Length < 1) { return(method); } var elements = new List <XElement>(); using (var reader = new StringReader(xmlComments.ToString())) using (var xml = XmlReader.Create(reader, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Fragment })) { try { xml.MoveToContent(); while (!xml.EOF) { if (xml.NodeType == XmlNodeType.Element) { elements.Add((XElement)XElement.ReadFrom(xml)); } else { xml.Read(); } } } catch (XmlException) { } } var builder = new StringBuilder(); foreach (var elem in elements.Where(e => e.Name.LocalName == "summary")) { BuildDocString(elem, builder); } method.Summary = builder.ToString().Trim(); foreach (var elem in elements.Where(e => e.Name.LocalName == "param")) { var xPath = new List <XPathToken>(); try { xPath = XPathToken.Parse((string)elem.Attribute("name")).ToList(); } catch (Exception) { } var stack = new Stack <AmlDocumentation>(); stack.Push(method); var idx = 0; while (idx < xPath.Count) { if (xPath[idx].TryGetAxis(out var axis) && axis == XPathAxis.Attribute && idx + 1 < xPath.Count) { var attrDoc = stack.Peek().GetOrAddAttribute(xPath[idx + 1].Value); stack.Push(attrDoc); idx++; }