Skip to content

Commit

Permalink
Style improvements for generated p/invokes (#69638)
Browse files Browse the repository at this point in the history
- Remove '_gen` part of suffix
- Remove unnecessary braces in fixed block
  • Loading branch information
elinor-fung committed May 21, 2022
1 parent 9a5387b commit 770f6ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public enum Stage
/// </summary>
public StubCodeContext? ParentContext { get; protected init; }

public const string GeneratedNativeIdentifierSuffix = "_gen_native";
public const string GeneratedNativeIdentifierSuffix = "_native";

/// <summary>
/// Get managed and native instance identifiers for the <paramref name="info"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,31 @@ private static FixedStatementSyntax AddStatementWithoutEmptyStatements(this Fixe
{
return fixedStatement.WithStatement(childStatement);
}

BlockSyntax block;
if (fixedStatement.Statement.IsKind(SyntaxKind.Block))
{
var block = (BlockSyntax)fixedStatement.Statement;
block = (BlockSyntax)fixedStatement.Statement;
if (block.Statements.Count == 0)
{
return fixedStatement.WithStatement(childStatement);
}
return fixedStatement.WithStatement(block.AddStatements(childStatement));
}
return fixedStatement.WithStatement(SyntaxFactory.Block(fixedStatement.Statement, childStatement));
else
{
block = SyntaxFactory.Block(fixedStatement.Statement);
}

if (childStatement.IsKind(SyntaxKind.Block))
{
block = block.WithStatements(block.Statements.AddRange(((BlockSyntax)childStatement).Statements));
}
else
{
block = block.AddStatements(childStatement);
}

return fixedStatement.WithStatement(block);
}

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

0 comments on commit 770f6ac

Please sign in to comment.