Skip to content

Commit e456b1e

Browse files
committed
Handle if disposing return. Simple case.
#176
1 parent d3f68e0 commit e456b1e

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

IDisposableAnalyzers.Test/IDISP023ReferenceTypeInFinalizerContextTests/Valid.Dispose.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,44 @@ protected override void Dispose(bool disposing)
405405

406406
RoslynAssert.Valid(Analyzer, DisposableCode, baseClass, code);
407407
}
408+
409+
[Test]
410+
public static void IfNotDisposingReturn()
411+
{
412+
var code = @"
413+
namespace N
414+
{
415+
using System;
416+
417+
public abstract class C : IDisposable
418+
{
419+
private readonly IDisposable disposable = new Disposable();
420+
private bool disposed;
421+
422+
public void Dispose()
423+
{
424+
this.Dispose(true);
425+
GC.SuppressFinalize(this);
426+
}
427+
428+
protected virtual void Dispose(bool disposing)
429+
{
430+
if (this.disposed)
431+
{
432+
return;
433+
}
434+
435+
this.disposed = true;
436+
if (!disposing)
437+
return;
438+
439+
disposable.Dispose();
440+
}
441+
}
442+
}";
443+
444+
RoslynAssert.Valid(Analyzer, DisposableCode, code);
445+
}
408446
}
409447
}
410448
}

IDisposableAnalyzers/Helpers/TestFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal static bool TryGetTearDownMethod(AttributeSyntax setupAttribute, Semant
7979

8080
return false;
8181

82-
QualifiedType? TearDown(ITypeSymbol? initialize)
82+
static QualifiedType? TearDown(ITypeSymbol? initialize)
8383
{
8484
if (initialize is null)
8585
{

0 commit comments

Comments
 (0)