Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -637,24 +637,15 @@ private static ClassDeclarationSyntax GenerateInterfaceInformation(ComInterfaceI

static ExpressionSyntax CreateEmbeddedDataBlobCreationStatement(ReadOnlySpan<byte> bytes)
{
var literals = new LiteralExpressionSyntax[bytes.Length];
var literals = new CollectionElementSyntax[bytes.Length];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this require language version guard?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Generally, we haven't been adding language version guards in the interop source generators. It's technically more correct to do so, but I'd rather hold off until we have a customer who explicitly downgrades the language version and files an issue with us before I add them.


for (int i = 0; i < bytes.Length; i++)
{
literals[i] = LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytes[i]));
literals[i] = ExpressionElement(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytes[i])));
}

// new System.ReadOnlySpan<byte>(new[] { <byte literals> } )
return ObjectCreationExpression(
GenericName(TypeNames.System_ReadOnlySpan)
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))
.AddArgumentListArguments(
Argument(
ArrayCreationExpression(
ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)), SingletonList(ArrayRankSpecifier())),
InitializerExpression(
SyntaxKind.ArrayInitializerExpression,
SeparatedList<ExpressionSyntax>(literals)))));
// [ <byte literals> ]
return CollectionExpression(SeparatedList(literals));
}
}
}
Expand Down