private IEnumerable <CSharpClassConstructor> GetConstructors(string className) { CSharpDocumentationComment docComment = new CSharpDocumentationComment(summary: null, rawNotes: "<inheritdoc />"); CSharpClassConstructor result = new CSharpClassConstructor( className, body: null, parameters: new CSharpParameter("requestTransmitter", typeof(IOperationInvocationTransmitter).GetCSharpName()).SingleObjectAsEnumerable(), baseClassConstructorParameterValues: "requestTransmitter".SingleObjectAsEnumerable(), documentationComment: docComment ); yield return(result); }
private IEnumerable <CSharpClassConstructor> GetConstructors(ContractDefinition contract, string className) { CSharpDocumentationComment docComment = new CSharpDocumentationComment(summary: null, rawNotes: "<inheritdoc />"); string contractImplementationParameterName = "contractImplementation"; CSharpClassConstructor result = new CSharpClassConstructor( className, body: null, parameters: new CSharpParameter(contractImplementationParameterName, contract.FullName).SingleObjectAsEnumerable(), baseClassConstructorParameterValues: contractImplementationParameterName.SingleObjectAsEnumerable(), documentationComment: docComment ); yield return(result); }
public static CSharpDocumentationComment ToCSharpDocumentationComment(this CmdletDocumentation cmdletDoc) { if (cmdletDoc == null) { throw new ArgumentNullException(nameof(cmdletDoc)); } StringBuilder summaryBuilder = new StringBuilder(); // Synopsis if (cmdletDoc.Synopsis != null) { summaryBuilder.AppendLine($"<para type=\"synopsis\">{cmdletDoc.Synopsis.EscapeForXml()}</para>"); } // Descriptions if (cmdletDoc.Descriptions != null) { foreach (string description in cmdletDoc.Descriptions.Where(desc => !string.IsNullOrWhiteSpace(desc))) { summaryBuilder.AppendLine($"<para type=\"description\">{description.EscapeForXml()}</para>"); } } StringBuilder notesBuilder = new StringBuilder(); // URLs if (cmdletDoc.Links != null) { foreach (CmdletDocumentationLink link in cmdletDoc.Links) { notesBuilder.AppendLine($@"<para type=""link"" uri=""{link.Url}"">{link.Name.EscapeForXml()}</para>"); } } // Compile the comments string summary = summaryBuilder.ToString().Trim(); string notes = notesBuilder.ToString().Trim(); // Create the result CSharpDocumentationComment result = new CSharpDocumentationComment() { Summary = string.IsNullOrWhiteSpace(summary) ? null : summary, RawNotes = string.IsNullOrWhiteSpace(notes) ? null : notes, }; return(result); }
private IEnumerable <CSharpMethod> GetMethods(IEnumerable <OperationDefinition> operations) { foreach (OperationDefinition operation in operations) { CSharpDocumentationComment docComment = new CSharpDocumentationComment(summary: null, rawNotes: operation.Description); bool isAsync = operation.ReturnsTask(out Type returnType); CSharpMethod result = new CSharpMethod( name: operation.Name, returnType: operation.ReturnType.GetCSharpName(), body: this.GetMethodBody(operation, isAsync, returnType), parameters: this.GetMethodParameters(operation), isAsync: isAsync, documentationComment: docComment); yield return(result); } }
public static CSharpDocumentationComment ToCSharpDocumentationComment(this CmdletParameterDocumentation paramDoc) { if (paramDoc == null) { throw new ArgumentNullException(nameof(paramDoc)); } StringBuilder summaryBuilder = new StringBuilder(); // Descriptions if (paramDoc.Descriptions != null) { foreach (string description in paramDoc.Descriptions.Where(desc => !string.IsNullOrWhiteSpace(desc))) { summaryBuilder.AppendLine($"<para type=\"description\">{description.EscapeForXml()}</para>"); } } // Valid values if (paramDoc.ValidValues != null && paramDoc.ValidValues.Any()) { string valueList = string.Join(", ", paramDoc.ValidValues.Select(val => $"'{val}'".EscapeForXml())); summaryBuilder.AppendLine("<para type=\"description\">"); summaryBuilder.AppendLine($" Valid values: {valueList}".Indent()); summaryBuilder.AppendLine("</para>"); } // Compile the comments string summary = summaryBuilder.ToString().Trim(); // Create the result CSharpDocumentationComment result = new CSharpDocumentationComment() { Summary = string.IsNullOrWhiteSpace(summary) ? null : summary, }; return(result); }
void CheckXmlDoc(AstNode node) { ResolveResult resolveResult = ctx.Resolve(node); IEntity member = null; if (resolveResult is TypeResolveResult) { member = resolveResult.Type.GetDefinition(); } if (resolveResult is MemberResolveResult) { member = ((MemberResolveResult)resolveResult).Member; } var xml = new StringBuilder(); var firstline = "<root>\n"; xml.Append(firstline); foreach (var cmt in storedXmlComment) { xml.Append(cmt.Content + "\n"); } xml.Append("</root>\n"); var doc = new AXmlParser().Parse(new StringTextSource(xml.ToString())); var stack = new Stack <AXmlObject>(); stack.Push(doc); foreach (var err in doc.SyntaxErrors) { AddXmlIssue(err.StartOffset - firstline.Length, err.EndOffset - err.StartOffset, err.Description); } while (stack.Count > 0) { var cur = stack.Pop(); var el = cur as AXmlElement; if (el != null) { switch (el.Name) { case "typeparam": case "typeparamref": var name = el.Attributes.FirstOrDefault(attr => attr.Name == "name"); if (name == null) { break; } if (member.SymbolKind == SymbolKind.TypeDefinition) { var type = (ITypeDefinition)member; if (!type.TypeArguments.Any(arg => arg.Name == name.Value)) { AddXmlIssue(name.ValueSegment.Offset - firstline.Length + 1, name.ValueSegment.Length - 2, string.Format(ctx.TranslateString("Type parameter '{0}' not found"), name.Value)); } } break; case "param": case "paramref": name = el.Attributes.FirstOrDefault(attr => attr.Name == "name"); if (name == null) { break; } var m = member as IParameterizedMember; if (m != null && m.Parameters.Any(p => p.Name == name.Value)) { break; } if (name.Value == "value" && (member.SymbolKind == SymbolKind.Property || member.SymbolKind == SymbolKind.Indexer || member.SymbolKind == SymbolKind.Event) && el.Name == "paramref") { break; } AddXmlIssue(name.ValueSegment.Offset - firstline.Length + 1, name.ValueSegment.Length - 2, string.Format(ctx.TranslateString("Parameter '{0}' not found"), name.Value)); break; case "exception": case "seealso": case "see": var cref = el.Attributes.FirstOrDefault(attr => attr.Name == "cref"); if (cref == null) { break; } try { var trctx = ctx.Resolver.TypeResolveContext; if (member is IMember) { trctx = trctx.WithCurrentTypeDefinition(member.DeclaringTypeDefinition).WithCurrentMember((IMember)member); } if (member is ITypeDefinition) { trctx = trctx.WithCurrentTypeDefinition((ITypeDefinition)member); } var state = ctx.Resolver.GetResolverStateBefore(node); if (state.CurrentUsingScope != null) { trctx = trctx.WithUsingScope(state.CurrentUsingScope); } var cdc = new CSharpDocumentationComment(emptySource, trctx); var entity = cdc.ResolveCref(cref.Value); if (entity == null) { AddXmlIssue(cref.ValueSegment.Offset - firstline.Length + 1, cref.ValueSegment.Length - 2, string.Format(ctx.TranslateString("Cannot find reference '{0}'"), cref.Value)); } } catch (Exception e) { AddXmlIssue(cref.ValueSegment.Offset - firstline.Length + 1, cref.ValueSegment.Length - 2, string.Format(ctx.TranslateString("Reference parsing error '{0}'."), e.Message)); } break; } } foreach (var child in cur.Children) { stack.Push(child); } } storedXmlComment.Clear(); }