Suppress finaliser in Dispose if there's a protected Dispose(bool)
Fixes #746
This commit is contained in:
@@ -3520,6 +3520,77 @@ null//comment
|
|||||||
Console.WriteLine("Done");
|
Console.WriteLine("Done");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
[Test]
|
||||||
|
public void DisposeSupressesFinalization()
|
||||||
|
{
|
||||||
|
UnmanagedResourceFakingJsonReader.CreateAndDispose();
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
Assert.AreEqual(1, UnmanagedResourceFakingJsonReader.DisposalCalls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UnmanagedResourceFakingJsonReader : JsonReader
|
||||||
|
{
|
||||||
|
public static int DisposalCalls;
|
||||||
|
|
||||||
|
public static void CreateAndDispose()
|
||||||
|
{
|
||||||
|
((IDisposable)new UnmanagedResourceFakingJsonReader()).Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnmanagedResourceFakingJsonReader()
|
||||||
|
{
|
||||||
|
DisposalCalls = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
base.Dispose(disposing);
|
||||||
|
++DisposalCalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
~UnmanagedResourceFakingJsonReader()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Read()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override byte[] ReadAsBytes()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override DateTime? ReadAsDateTime()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !NET20
|
||||||
|
public override DateTimeOffset? ReadAsDateTimeOffset()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public override decimal? ReadAsDecimal()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int? ReadAsInt32()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ReadAsString()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ToggleReaderError : TextReader
|
public class ToggleReaderError : TextReader
|
||||||
|
|||||||
@@ -1085,6 +1085,7 @@ namespace Newtonsoft.Json
|
|||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user