File tree Expand file tree Collapse file tree
IDisposableAnalyzers.Test/IDISP011DontReturnDisposedTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1107,5 +1107,36 @@ public Stream DisposeBefore(string[] fileNames)
11071107}" ;
11081108 RoslynAssert . Valid ( Analyzer , code ) ;
11091109 }
1110+
1111+ [ Test ]
1112+ public static void DisposedInCatchThenRethrow ( )
1113+ {
1114+ var code = @"
1115+ namespace N
1116+ {
1117+ using System;
1118+ using System.IO;
1119+
1120+ public class C
1121+ {
1122+ public MemoryStream M()
1123+ {
1124+ var ms = new MemoryStream();
1125+ try
1126+ {
1127+ }
1128+ catch (Exception)
1129+ {
1130+ ms.Dispose();
1131+ throw;
1132+ }
1133+
1134+ return ms;
1135+ }
1136+ }
1137+ }
1138+ " ;
1139+ RoslynAssert . Valid ( Analyzer , code ) ;
1140+ }
11101141 }
11111142}
Original file line number Diff line number Diff line change 1+ namespace ValidCode
2+ {
3+ using System ;
4+ using System . IO ;
5+
6+ public class Throws
7+ {
8+ public MemoryStream DisposeInThrow ( )
9+ {
10+ var ms = new MemoryStream ( ) ;
11+ try
12+ {
13+ }
14+ catch ( Exception )
15+ {
16+ ms . Dispose ( ) ;
17+ throw ;
18+ }
19+
20+ return ms ;
21+ }
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments