File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
ReadableExpressions.UnitTests
ReadableExpressions/Extensions Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -389,6 +389,35 @@ public void ShouldIncludeAReturnKeywordForANewObjectStatement()
389389 Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
390390 }
391391
392+ [ TestMethod ]
393+ public void ShouldIncludeAReturnKeywordForANewListInitStatement ( )
394+ {
395+ var exception = Expression . Variable ( typeof ( Exception ) , "ex" ) ;
396+ var listConstructor = typeof ( List < int > ) . GetConstructor ( new [ ] { typeof ( int ) } ) ;
397+ var one = Expression . Constant ( 1 ) ;
398+ // ReSharper disable once AssignNullToNotNullAttribute
399+ var newList = Expression . New ( listConstructor , one ) ;
400+ var newListInit = Expression . ListInit ( newList , one ) ;
401+ var rethrow = Expression . Rethrow ( newListInit . Type ) ;
402+ var globalCatchAndRethrow = Expression . Catch ( exception , rethrow ) ;
403+ var tryCatch = Expression . TryCatch ( newListInit , globalCatchAndRethrow ) ;
404+
405+ var tryCatchBlock = Expression . Block ( tryCatch ) ;
406+
407+ var translated = tryCatchBlock . ToReadableString ( ) ;
408+
409+ const string EXPECTED = @"
410+ try
411+ {
412+ return new List<int>(1) { 1 };
413+ }
414+ catch
415+ {
416+ throw;
417+ }" ;
418+ Assert . AreEqual ( EXPECTED . TrimStart ( ) , translated ) ;
419+ }
420+
392421 [ TestMethod ]
393422 public void ShouldIncludeAReturnKeywordForANewArrayStatement ( )
394423 {
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ public static bool IsReturnable(this Expression expression)
3232 case ExpressionType . Default :
3333 case ExpressionType . Divide :
3434 case ExpressionType . Invoke :
35+ case ExpressionType . ListInit :
3536 case ExpressionType . MemberAccess :
3637 case ExpressionType . Multiply :
3738 case ExpressionType . MultiplyChecked :
You can’t perform that action at this time.
0 commit comments