/// <summary> /// Adds disposable feature. /// </summary> /// <param name="package">Package to add disposable feature to.</param> public static void AddDisposableFeature(this OpenXmlPackage package) { if (package.Features.Get <IDisposableFeature>() is not null) { return; } package.AddPartEventsFeature(); package.AddPackageEventsFeature(); package.Features.AddDisposableFeature(); // Add feature to all parts already created foreach (var part in package.GetAllParts()) { part.Features.AddDisposableFeature(); } }