Skip to content

Commit ff30b59

Browse files
committed
Test confirm already fixed.
Close #184
1 parent 15c7564 commit ff30b59

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

IDisposableAnalyzers.Test/IDISP011DontReturnDisposedTests/Valid.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

ValidCode/Throws.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

0 commit comments

Comments
 (0)