@@ -6281,7 +6281,7 @@ internal static StringBuilder ToCSharpString(this Expression e, StringBuilder sb
6281
6281
{
6282
6282
var x = ( ConstantExpression ) e ;
6283
6283
if ( x . Value == null )
6284
- return x . Type != null
6284
+ return x . Type != null && x . Type . IsValueType
6285
6285
? sb . Append ( "default(" ) . Append ( x . Type . ToCode ( stripNamespace , printType ) ) . Append ( ')' )
6286
6286
: sb . Append ( "null" ) ;
6287
6287
@@ -6468,7 +6468,7 @@ internal static StringBuilder ToCSharpString(this Expression e, StringBuilder sb
6468
6468
sb . NewLineIdentCs ( body , lineIdent , stripNamespace , printType , identSpaces , notRecognizedToCode ) ;
6469
6469
else
6470
6470
{
6471
- sb . NewLine ( lineIdent , identSpaces ) . Append ( '{' ) ;
6471
+ sb . NewLineIdent ( lineIdent ) . Append ( '{' ) ;
6472
6472
6473
6473
// Body handles `;` itself
6474
6474
if ( body is BlockExpression bb )
@@ -6479,7 +6479,7 @@ internal static StringBuilder ToCSharpString(this Expression e, StringBuilder sb
6479
6479
if ( isBodyExpression )
6480
6480
sb . AddSemicolonIfFits ( ) ;
6481
6481
}
6482
- sb . NewLine ( lineIdent , identSpaces ) . Append ( '}' ) ;
6482
+ sb . NewLineIdent ( lineIdent ) . Append ( '}' ) ;
6483
6483
}
6484
6484
return sb . Append ( ')' ) ;
6485
6485
}
@@ -6533,7 +6533,14 @@ internal static StringBuilder ToCSharpString(this Expression e, StringBuilder sb
6533
6533
}
6534
6534
case ExpressionType . Block :
6535
6535
{
6536
- return BlockToCSharpString ( ( BlockExpression ) e , sb , lineIdent , stripNamespace , printType , identSpaces , notRecognizedToCode : notRecognizedToCode ) ;
6536
+ if ( enclosedIn == EnclosedIn . Block )
6537
+ return BlockToCSharpString ( ( BlockExpression ) e , sb , lineIdent , stripNamespace , printType , identSpaces , notRecognizedToCode : notRecognizedToCode ) ;
6538
+ else
6539
+ {
6540
+ sb . Append ( '{' ) ;
6541
+ BlockToCSharpString ( ( BlockExpression ) e , sb , lineIdent + identSpaces , stripNamespace , printType , identSpaces , notRecognizedToCode : notRecognizedToCode ) ;
6542
+ return sb . AddSemicolonIfFits ( ) . NewLineIdent ( lineIdent ) . Append ( '}' ) ;
6543
+ }
6537
6544
}
6538
6545
case ExpressionType . Loop :
6539
6546
{
@@ -6684,11 +6691,12 @@ void PrintPart(Expression part)
6684
6691
}
6685
6692
case ExpressionType . Default :
6686
6693
{
6687
- return e . Type == typeof ( void ) ? sb // `default(void)` does not make sense in the C#
6688
- : sb . Append ( "default(" ) . Append ( e . Type . ToCode ( stripNamespace , printType ) ) . Append ( ')' ) ;
6694
+ return e . Type == typeof ( void ) ? sb : // `default(void)` does not make sense in the C#
6695
+ ! e . Type . IsValueType && ! e . Type . IsGenericParameter ? sb . Append ( "null" ) :
6696
+ sb . Append ( "default(" ) . Append ( e . Type . ToCode ( stripNamespace , printType ) ) . Append ( ')' ) ;
6689
6697
}
6690
6698
case ExpressionType . TypeIs :
6691
- case ExpressionType . TypeEqual :
6699
+ case ExpressionType . TypeEqual : // TODO: type equal
6692
6700
{
6693
6701
var x = ( TypeBinaryExpression ) e ;
6694
6702
sb . Append ( '(' ) ;
@@ -7598,4 +7606,4 @@ public static IReadOnlyList<PE> ToReadOnlyList(this IParameterProvider source)
7598
7606
public static IReadOnlyList < PE > ToReadOnlyList ( this IReadOnlyList < PE > source ) => source ;
7599
7607
#endif
7600
7608
}
7601
- }
7609
+ }
0 commit comments