Files
speckle-sharp-connectors/Sdk/Speckle.Converters.Common/ConverterSettingsStore.cs
T
Claire Kuang 74982e025b Revert "Merge branch 'dev' into grasshopper"
This reverts commit 8bcc70cced, reversing
changes made to 2ae80cc7ba.
2025-04-21 12:52:26 +01:00

32 lines
760 B
C#

namespace Speckle.Converters.Common;
public sealed class ConverterSettingsStore<T> : IConverterSettingsStore<T>
where T : class
{
private readonly Stack<T> _stack = new();
public T Current => _stack.Peek();
public IDisposable Push(Func<T, T> nextContext)
{
_stack.Push(nextContext(Current));
return new ContextWrapper(this);
}
public void Initialize(T context)
{
if (_stack.Count != 0)
{
throw new ArgumentException("Already initialized");
}
_stack.Push(context);
}
private sealed class ContextWrapper(ConverterSettingsStore<T> store) : IDisposable
{
public void Dispose() =>
// technically we could be popping something not this but throwing in dispose is bad
store._stack.Pop();
}
}