-Fixed JsonWriter IDisposable implementation
This commit is contained in:
@@ -1552,6 +1552,15 @@ null//comment
|
|||||||
]/*comment*/
|
]/*comment*/
|
||||||
}/*comment *//*comment 1 */", sw.ToString());
|
}/*comment *//*comment 1 */", sw.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DisposeSupressesFinalization()
|
||||||
|
{
|
||||||
|
UnmanagedResourceFakingJsonWriter.CreateAndDispose();
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
Assert.AreEqual(1, UnmanagedResourceFakingJsonWriter.DisposalCalls);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomJsonTextWriter : JsonTextWriter
|
public class CustomJsonTextWriter : JsonTextWriter
|
||||||
@@ -1720,4 +1729,35 @@ null//comment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
public class UnmanagedResourceFakingJsonWriter : JsonWriter
|
||||||
|
{
|
||||||
|
public static int DisposalCalls;
|
||||||
|
|
||||||
|
public static void CreateAndDispose()
|
||||||
|
{
|
||||||
|
((IDisposable)new UnmanagedResourceFakingJsonWriter()).Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnmanagedResourceFakingJsonWriter()
|
||||||
|
{
|
||||||
|
DisposalCalls = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
base.Dispose(disposing);
|
||||||
|
++DisposalCalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
~UnmanagedResourceFakingJsonWriter()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Flush()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1437,9 +1437,14 @@ namespace Newtonsoft.Json
|
|||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dispose(bool disposing)
|
/// <summary>
|
||||||
|
/// Releases unmanaged and - optionally - managed resources
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (_currentState != State.Closed)
|
if (_currentState != State.Closed)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user