using System; using System.Collections.Generic; namespace Unity.VisualScripting { public sealed class CloningContext : IPoolable, IDisposable { public Dictionary clonings { get; } = new Dictionary(ReferenceEqualityComparer.Instance); public ICloner fallbackCloner { get; private set; } public bool tryPreserveInstances { get; private set; } private bool disposed; void IPoolable.New() { disposed = false; } void IPoolable.Free() { disposed = true; clonings.Clear(); } public void Dispose() { if (disposed) { throw new ObjectDisposedException(ToString()); } GenericPool.Free(this); } public static CloningContext New(ICloner fallbackCloner, bool tryPreserveInstances) { var context = GenericPool.New(() => new CloningContext()); context.fallbackCloner = fallbackCloner; context.tryPreserveInstances = tryPreserveInstances; return context; } } }