Skip to content

Commit 770f6ac

Browse files
authored
Style improvements for generated p/invokes (#69638)
- Remove '_gen` part of suffix - Remove unnecessary braces in fixed block
1 parent 9a5387b commit 770f6ac

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StubCodeContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public enum Stage
9191
/// </summary>
9292
public StubCodeContext? ParentContext { get; protected init; }
9393

94-
public const string GeneratedNativeIdentifierSuffix = "_gen_native";
94+
public const string GeneratedNativeIdentifierSuffix = "_native";
9595

9696
/// <summary>
9797
/// Get managed and native instance identifiers for the <paramref name="info"/>

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SyntaxExtensions.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@ private static FixedStatementSyntax AddStatementWithoutEmptyStatements(this Fixe
1919
{
2020
return fixedStatement.WithStatement(childStatement);
2121
}
22+
23+
BlockSyntax block;
2224
if (fixedStatement.Statement.IsKind(SyntaxKind.Block))
2325
{
24-
var block = (BlockSyntax)fixedStatement.Statement;
26+
block = (BlockSyntax)fixedStatement.Statement;
2527
if (block.Statements.Count == 0)
2628
{
2729
return fixedStatement.WithStatement(childStatement);
2830
}
29-
return fixedStatement.WithStatement(block.AddStatements(childStatement));
3031
}
31-
return fixedStatement.WithStatement(SyntaxFactory.Block(fixedStatement.Statement, childStatement));
32+
else
33+
{
34+
block = SyntaxFactory.Block(fixedStatement.Statement);
35+
}
36+
37+
if (childStatement.IsKind(SyntaxKind.Block))
38+
{
39+
block = block.WithStatements(block.Statements.AddRange(((BlockSyntax)childStatement).Statements));
40+
}
41+
else
42+
{
43+
block = block.AddStatements(childStatement);
44+
}
45+
46+
return fixedStatement.WithStatement(block);
3247
}
3348

3449
public static StatementSyntax NestFixedStatements(this ImmutableArray<FixedStatementSyntax> fixedStatements, StatementSyntax innerStatement)

0 commit comments

Comments
 (0)