From cf2fddf76028274fe876c22785356c6bf1c7f7d7 Mon Sep 17 00:00:00 2001 From: Yulong Wang Date: Wed, 15 Apr 2020 10:30:11 -0700 Subject: [PATCH] fix nuget build (#3532) --- .../InferenceTest.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs index 86d9af68a8..d99dce3508 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs @@ -1836,4 +1836,44 @@ namespace Microsoft.ML.OnnxRuntime.Tests } } + + // A Disposable list is a list of IDisposable objects. All elements will be disposed when the container is disposed. + internal class DisposableList : List, IDisposableReadOnlyCollection + where T : IDisposable + { + public DisposableList() { } + public DisposableList(int count) : base(count) { } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + for (int i = 0; i < this.Count; i++) + { + this[i]?.Dispose(); + } + this.Clear(); + } + + disposedValue = true; + } + } + + ~DisposableList() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } }