74982e025b
This reverts commit8bcc70cced, reversing changes made to2ae80cc7ba.
32 lines
760 B
C#
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();
|
|
}
|
|
}
|