@ -392,28 +392,30 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public override void VisitInterpolation ( Interpolation interpolation )
public override void VisitInterpolation ( Interpolation interpolation )
{
{
// Need to do this first, in case the descendents parenthesize themselves.
base . VisitInterpolation ( interpolation ) ;
// If an interpolation contains global::, we need to parenthesize the expression.
// If an interpolation contains global::, we need to parenthesize the expression.
if ( InterpolationNeedsParenthesized ( interpolation ) )
if ( InterpolationNeedsParenthesis ( interpolation ) )
Parenthesize ( interpolation . Expression ) ;
Parenthesize ( interpolation . Expression ) ;
base . VisitInterpolation ( interpolation ) ;
static bool InterpolationNeedsParenthesized ( AstNode node )
static bool InterpolationNeedsParenthesis ( AstNode node )
{
{
if ( node is MemberType { IsDoubleColon : true } )
if ( node is MemberType { IsDoubleColon : true } )
return true ;
return true ;
if ( node is Conditional Expression)
if ( node is Parenthesized Expression)
return false ; // Conditional expressions are parenthesized in their own visit method.
return false ;
if ( node is AnonymousMethodExpression or LambdaExpression )
if ( node is AnonymousMethodExpression or LambdaExpression { Body : BlockStatement } )
return false ;
return false ;
if ( node is InvocationExpression invocation )
if ( node is InvocationExpression invocation )
return InterpolationNeedsParenthesized ( invocation . Target ) ;
return InterpolationNeedsParenthesis ( invocation . Target ) ;
if ( node is CastExpression cast )
if ( node is CastExpression cast )
return InterpolationNeedsParenthesized ( cast . Expression ) ;
return InterpolationNeedsParenthesis ( cast . Expression ) ;
foreach ( var child in node . Children )
foreach ( var child in node . Children )
{
{
if ( InterpolationNeedsParenthesized ( child ) )
if ( InterpolationNeedsParenthesis ( child ) )
return true ;
return true ;
}
}
return false ;
return false ;