Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dpaoliello
Copy link
Contributor

It's possible for C++ annotate attributes to contain strings literals, thus they should be correctly escaped before generating the corresponding C# attribute. The easiest way to do this is to use C# verbatim strings, and escape double-quotes (by adding a double-quote).

{
var annotationText = attr.Spelling;
outputBuilder.WriteCustomAttribute($"""NativeAnnotation("{annotationText}")""");
var annotationText = attr.Spelling.Replace("\"", "\"\"", StringComparison.Ordinal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should rather use the EscapeString(string value) helper which centralizes all the escape string handling and attempts to handle already escaped sequences as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tannergooding tannergooding merged commit c5a6a76 into dotnet:main Sep 24, 2024
13 checks passed
@dpaoliello dpaoliello deleted the escann branch September 24, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants