using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Reflection; using System.Xml.XPath; using System.Xml.Linq; using System.Text.RegularExpressions; using SDKDocGenerator.Syntax; namespace SDKDocGenerator.Writers { public class MethodWriter : MethodBaseWriter { readonly MethodInfoWrapper _methodInfo; readonly bool _isFakeAsync; readonly bool _hasAsyncVersion; public MethodWriter(GenerationManifest artifacts, FrameworkVersion version, MethodInfoWrapper methodInfo) : base(artifacts, version, methodInfo) { this._methodInfo = methodInfo; this._isFakeAsync = this._methodInfo.FullName == "Amazon.Lambda.Model.InvokeAsyncResponse InvokeAsync(Amazon.Lambda.Model.InvokeAsyncRequest)"; if (_isFakeAsync || !this._methodInfo.Name.EndsWith("Async", StringComparison.Ordinal)) { //This is not an Async method. Lookup if an Async version exists for .NET Core. this._hasAsyncVersion = NDocUtilities.FindDocumentationAsync(Artifacts.NDocForPlatform("netcoreapp3.1"), methodInfo) != null; } } protected override string GenerateFilename() { return FilenameGenerator.GenerateFilename(this._methodInfo); } protected override string GenerateFilepath() { return GenerationManifest.OutputSubFolderFromNamespace(_methodInfo.DeclaringType.Namespace); } protected override string GetTitle() { var par = FormatParameters(this._methodInfo.GetParameters()); if (string.IsNullOrEmpty(par)) return string.Format("{0}.{1} {2}", this._methodInfo.DeclaringType.GetDisplayName(false), this._methodInfo.Name, GetMemberType()); return string.Format("{0}.{1} {2} ({3})", this._methodInfo.DeclaringType.GetDisplayName(false), this._methodInfo.Name, GetMemberType(), par); } protected override string GetMemberName() { var par = FormatParameters(this._methodInfo.GetParameters()); if (string.IsNullOrEmpty(par)) return string.Format("{0}.{1}", this._methodInfo.DeclaringType.GetDisplayName(false), this._methodInfo.Name); return string.Format("{0}.{1} ({2})", this._methodInfo.DeclaringType.GetDisplayName(false), this._methodInfo.Name, par); } protected override string GetMemberType() { return "Method"; } protected override XElement GetSummaryDocumentation() { var element = NDocUtilities.FindDocumentation(this._methodInfo); return element; } protected override string GetSyntax() { return new CSharpSyntaxGenerator(this._version).GenerateSyntax(this._methodInfo); } protected override void AddReturn(System.IO.TextWriter writer) { var returnType = this._methodInfo.ReturnType; if (returnType == null || returnType.FullName == "System.Void") return; writer.WriteLine("
This is an asynchronous operation using the standard naming convention for .NET 4.5 or higher." + "{0}
For {0} this operation is only available in asynchronous form. Please refer to {1}Async.