public OperationElement GetOrAddAttribute(string name) { _attributes = _attributes ?? new List <OperationElement>(); var attr = _attributes.FirstOrDefault(d => d.Name == name); if (attr == null) { attr = new OperationElement() { Name = name }; _attributes.Add(attr); } return(attr); }
public OperationElement GetOrAddElement(string name) { _elements = _elements ?? new List <OperationElement>(); var element = _elements.FirstOrDefault(d => d.Name == name); if (element == null) { element = new OperationElement() { Name = name }; _elements.Add(element); } return(element); }
private static OperationElement Parse(string methodName, IEnumerable <XElement> elements) { var method = new OperationElement { Name = methodName }; var builder = new StringBuilder(); method.Summary.AddRange(elements .Where(e => e.Name.LocalName == "summary") .SelectMany(e => ParseDoc(e.Nodes()))); foreach (var elem in elements.Where(e => e.Name.LocalName == "inheritdoc")) { if (Standard.TryGetValue((string)elem.Attribute("cref"), out var doc)) { method.WithAttributes(doc.Attributes); method.WithElements(doc.Elements.ToArray()); if (method.Summary.Count < 1 && doc.Summary.Count > 0) { method.Summary.AddRange(doc.Summary); } } } 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 <OperationElement>(); 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++; }
internal static ListItem Parse(XElement element) { var result = new ListItem(); var term = element.Element("term"); if (term != null) { result.Term.AddRange(OperationElement.ParseDoc(term.Nodes())); } var description = element.Element("description"); if (description != null) { result.Description.AddRange(OperationElement.ParseDoc(description.Nodes())); } return(result); }
private static bool TryGetConstant(OperationElement operation, out string value) { value = null; if (!operation.ValueTypes.Any() || operation.ValueTypes.Skip(1).Any()) { return(false); } if (operation.ValueTypes.Single().Type != AmlDataType.Enum) { return(false); } if (!operation.ValueTypes.Single().Values.Any() || operation.ValueTypes.Single().Values.Skip(1).Any()) { return(false); } value = operation.ValueTypes.Single().Values.Single(); return(true); }
private static void BuildMethodCall(ElementFactory aml, Innovator.Client.IElement element, OperationElement operation) { foreach (var attribute in operation.Attributes) { element.Add(aml.Attribute(attribute.Name, TryGetConstant(attribute, out var constValue) ? constValue : "")); } foreach (var child in operation.Elements) { var newElement = default(Innovator.Client.IElement); switch (child.Name) { case "Relationships": newElement = aml.Relationships(); break; case "Item": newElement = aml.Item(); break; default: newElement = aml.Property(child.Name); if (TryGetConstant(child, out var constValue)) { newElement.Add(constValue); } break; } BuildMethodCall(aml, newElement, child); element.Add(newElement); } }