45 lines
971 B
C#
45 lines
971 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace FlowScope.Resources
|
|
{
|
|
public sealed class ResourceGroup : IResourceGroup
|
|
{
|
|
private readonly HashSet<IDisposable> _handles = new();
|
|
private bool _disposed;
|
|
|
|
public int Count => _handles.Count;
|
|
|
|
public void Add<T>(IResourceHandle<T> handle) where T : class
|
|
{
|
|
if (_disposed)
|
|
{
|
|
throw new ObjectDisposedException(nameof(ResourceGroup));
|
|
}
|
|
|
|
if (handle == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(handle));
|
|
}
|
|
|
|
_handles.Add(handle);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_disposed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_disposed = true;
|
|
foreach (var handle in _handles)
|
|
{
|
|
handle.Dispose();
|
|
}
|
|
|
|
_handles.Clear();
|
|
}
|
|
}
|
|
}
|