public void ReturnInstance(T instance) { ReturnInstanceTask?.Invoke(instance); if (objectStack.Count < targetCount) { objectStack.Push(instance); } else { DisposeInstanceTask?.Invoke(instance); } }
public void CreateInstance(int count) { if (count == 0) { return; } this.targetCount += count; for (int i = 0; i < count; ++i) { T instance; if (CreateInstanceMethod != null) { instance = CreateInstanceMethod(); } else { instance = default(T); } ReturnInstanceTask?.Invoke(instance); objectStack.Push(instance); } }