新增 FlowScope Git 包雏形
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user