Skip to content

Commit 7549fb2

Browse files
committed
make ISource IDisposable, fixes #33
1 parent 7411b5e commit 7549fb2

File tree

10 files changed

+48
-5
lines changed

10 files changed

+48
-5
lines changed

RELEASE_NOTES.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Release Notes
22

3-
## XMLUnit.NET 2.8.1 - /not released, yet/
3+
## XMLUnit.NET 2.9.0 - /not released, yet/
4+
5+
* `ISource` now extends `IDisposable` to allow releasing unmanaged
6+
resources used when building sources from files or URIs.
7+
8+
This change is backwards incompatible if you are providing `ISource`
9+
implementations of your own.
10+
[#33](https://github.com/xmlunit/xmlunit.net/pull/33).
411

512
## XMLUnit.NET 2.8.0 - /Released 2020-05-12/
613

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.8.1.{build}
1+
version: 2.9.0.{build}
22

33
image:
44
- Visual Studio 2013

src/doc/monodoc/core/index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@
4545
under <format type="text/html"><a href="https://github.com/xmlunit/xmlunit.net/blob/main/LICENSE">the
4646
Apache License, Version 2.0</a></format>.</para></Remarks>
4747
<Copyright></Copyright>
48-
<Title>XMLUnit.NET 2.8.1-alpha-01</Title>
48+
<Title>XMLUnit.NET 2.9.0-alpha-01</Title>
4949
</Overview>

src/main/net-core/ISource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Org.XmlUnit {
1818
/// Representation of the various ways to provide pieces of XML to
1919
/// XMLUnit.
2020
/// </summary>
21-
public interface ISource {
21+
public interface ISource : System.IDisposable {
2222
/// <summary>
2323
/// Provides the content.
2424
/// </summary>

src/main/net-core/Input/AbstractSource.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Org.XmlUnit.Input
2121
/// </summary>
2222
public abstract class AbstractSource : ISource
2323
{
24+
private bool disposed;
2425
private string systemId;
2526
private readonly XmlReader reader;
2627
/// <summary>
@@ -61,5 +62,16 @@ public override string ToString()
6162
return string.Format("{0} with systemId {1}", GetType().Name,
6263
SystemId);
6364
}
65+
66+
public void Dispose() {
67+
Dispose(false);
68+
}
69+
70+
protected virtual void Dispose(bool disposing) {
71+
if (!disposed) {
72+
reader.Close();
73+
disposed = true;
74+
}
75+
}
6476
}
6577
}

src/main/net-core/Input/ByteArraySource.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ public override string ToString()
5959
{
6060
return string.Format("ByteArraySource with systemId {0}", SystemId);
6161
}
62+
63+
public void Dispose() { }
6264
}
6365
}

src/main/net-core/Input/CommentLessSource.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace Org.XmlUnit.Input {
3131
/// </para>
3232
/// </remarks>
3333
public sealed class CommentLessSource : ISource {
34+
private bool disposed;
3435
private readonly XmlReader reader;
3536
private string systemId;
3637

@@ -100,6 +101,13 @@ public string SystemId
100101
}
101102
}
102103

104+
public void Dispose() {
105+
if (!disposed) {
106+
reader.Close();
107+
disposed = true;
108+
}
109+
}
110+
103111
private static ISource GetStylesheet(string xsltVersion) {
104112
return new StreamSource(new System.IO.StringReader(GetStylesheetContentCached(xsltVersion)));
105113
}

src/main/net-core/Input/NormalizedSource.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace Org.XmlUnit.Input {
3636
/// </para>
3737
/// </remarks>
3838
public class NormalizedSource : ISource {
39+
private bool disposed;
3940
private string systemId;
4041
private readonly XmlReader reader;
4142
private readonly XmlNode node;
@@ -107,5 +108,16 @@ public override string ToString()
107108
return string.Format("{0} with systemId {1}", GetType().Name,
108109
SystemId);
109110
}
111+
112+
public void Dispose() {
113+
Dispose(false);
114+
}
115+
116+
protected virtual void Dispose(bool disposing) {
117+
if (!disposed) {
118+
reader.Close();
119+
disposed = true;
120+
}
121+
}
110122
}
111123
}

src/main/net-core/Input/StringSource.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ public override string ToString()
6060
return string.Format("StringSource with content{0} and systemId {1}", content,
6161
SystemId);
6262
}
63+
64+
public void Dispose() { }
6365
}
6466
}

src/shared/CommonAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Org.XmlUnit
2525
{
2626
internal static class XmlUnitVersion
2727
{
28-
internal const string ApiVersion = "2.8.1";
28+
internal const string ApiVersion = "2.9.0";
2929
internal const string AssemblyVersion = ApiVersion + ".198";
3030
internal const string Version = ApiVersion + "-alpha-01";
3131
}

0 commit comments

Comments
 (0)