Skip to content

Commit

Permalink
Add [DebuggerDisplay] attribute to typedef structs
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Feb 16, 2021
1 parent 1be7efb commit 4f54561
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,13 @@ private static AttributeSyntax DebuggerBrowsable(DebuggerBrowsableState state)
IdentifierName(Enum.GetName(typeof(DebuggerBrowsableState), state)!))));
}

private static AttributeSyntax DebuggerDisplay(string format)
{
return Attribute(IdentifierName("DebuggerDisplay"))
.AddArgumentListArguments(
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(format))));
}

private static SyntaxToken SafeIdentifier(string name) => SafeIdentifierName(name).Identifier;

private static IdentifierNameSyntax SafeIdentifierName(string name) => IdentifierName(CSharpKeywords.Contains(name) ? "@" + name : name);
Expand Down Expand Up @@ -2081,7 +2088,8 @@ private StructDeclarationSyntax CreateTypeDefStruct(TypeDefinition typeDef)
StructDeclarationSyntax result = StructDeclaration(name)
.AddBaseListTypes(SimpleBaseType(GenericName(nameof(IEquatable<int>)).AddTypeArgumentListArguments(IdentifierName(name))))
.WithMembers(members)
.WithModifiers(TokenList(Token(this.Visibility), Token(SyntaxKind.ReadOnlyKeyword), Token(SyntaxKind.PartialKeyword)));
.WithModifiers(TokenList(Token(this.Visibility), Token(SyntaxKind.ReadOnlyKeyword), Token(SyntaxKind.PartialKeyword)))
.AddAttributeLists(AttributeList().AddAttributes(DebuggerDisplay("{" + fieldName + "}")));

result = AddApiDocumentation(name, result);
return result;
Expand Down

0 comments on commit 4f54561

Please sign in to comment.