Skip to content

Commit

Permalink
Merge pull request #168 from microsoft/fix22
Browse files Browse the repository at this point in the history
Add documentation about constants
  • Loading branch information
AArnott authored Mar 3, 2021
2 parents f936f9d + 90698c9 commit fb25c3e
Show file tree
Hide file tree
Showing 3 changed files with 436 additions and 158 deletions.
29 changes: 17 additions & 12 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,9 @@ internal void GenerateConstant(FieldDefinitionHandle fieldDefHandle)
return;
}

this.fieldsToSyntax.Add(fieldDefHandle, this.CreateField(fieldDefHandle));
FieldDeclarationSyntax constantDeclaration = this.CreateField(fieldDefHandle);
constantDeclaration = AddApiDocumentation(constantDeclaration.Declaration.Variables[0].Identifier.ValueText, constantDeclaration);
this.fieldsToSyntax.Add(fieldDefHandle, constantDeclaration);
}

internal TypeSyntax? GenerateSafeHandle(string releaseMethod)
Expand Down Expand Up @@ -1208,19 +1210,22 @@ private static T AddApiDocumentation<T>(string api, T memberDeclaration)
docCommentsBuilder.AppendLine("</returns>");
}

docCommentsBuilder.Append($"/// <remarks>");
if (docs.Remarks is object)
if (docs.Remarks is object || docs.HelpLink is object)
{
EmitDoc(docs.Remarks, docCommentsBuilder, docs, string.Empty);
}
else
{
docCommentsBuilder.AppendLine();
docCommentsBuilder.AppendLine($@"/// <para><see href=""{docs.HelpLink}"">Learn more about this API from docs.microsoft.com</see>.</para>");
docCommentsBuilder.Append("/// ");
}
docCommentsBuilder.Append($"/// <remarks>");
if (docs.Remarks is object)
{
EmitDoc(docs.Remarks, docCommentsBuilder, docs, string.Empty);
}
else if (docs.HelpLink is object)
{
docCommentsBuilder.AppendLine();
docCommentsBuilder.AppendLine($@"/// <para><see href=""{docs.HelpLink}"">Learn more about this API from docs.microsoft.com</see>.</para>");
docCommentsBuilder.Append("/// ");
}

docCommentsBuilder.AppendLine($"</remarks>");
docCommentsBuilder.AppendLine($"</remarks>");
}

memberDeclaration = memberDeclaration.WithLeadingTrivia(
ParseLeadingTrivia(docCommentsBuilder.ToString()));
Expand Down
70 changes: 70 additions & 0 deletions src/ScrapeDocs/DocEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace ScrapeDocs
{
using System.Collections.Generic;

internal class DocEnum
{
internal DocEnum(bool isFlags, IReadOnlyDictionary<string, string?> memberNamesAndDocs)
{
this.IsFlags = isFlags;
this.MemberNamesAndDocs = memberNamesAndDocs;
}

internal bool IsFlags { get; }

internal IReadOnlyDictionary<string, string?> MemberNamesAndDocs { get; }

public override bool Equals(object? obj) => this.Equals(obj as DocEnum);

public override int GetHashCode()
{
unchecked
{
int hash = this.IsFlags ? 1 : 0;
foreach (KeyValuePair<string, string?> entry in this.MemberNamesAndDocs)
{
hash += entry.Key.GetHashCode();
hash += entry.Value?.GetHashCode() ?? 0;
}

return hash;
}
}

public bool Equals(DocEnum? other)
{
if (other is null)
{
return false;
}

if (this.IsFlags != other.IsFlags)
{
return false;
}

if (this.MemberNamesAndDocs.Count != other.MemberNamesAndDocs.Count)
{
return false;
}

foreach (KeyValuePair<string, string?> entry in this.MemberNamesAndDocs)
{
if (!other.MemberNamesAndDocs.TryGetValue(entry.Key, out string? value))
{
return false;
}

if (entry.Value != value)
{
return false;
}
}

return true;
}
}
}
Loading

0 comments on commit fb25c3e

Please sign in to comment.