From 74489afc252378b9c098434715c7b1a3ef57c592 Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Mon, 7 Oct 2024 13:48:42 +1300 Subject: [PATCH] Dispose objects before they lose scope (CA2000) --- .../OLEProperties/OLEPropertiesContainer.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs b/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs index c2fa0feb..a496c8b6 100644 --- a/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs +++ b/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs @@ -84,7 +84,10 @@ internal OLEPropertiesContainer(CFStream cfStream) PropertySetStream pStream = new PropertySetStream(); this.cfStream = cfStream; - pStream.Read(new BinaryReader(new StreamDecorator(cfStream))); + + using StreamDecorator stream = new(cfStream); + using BinaryReader reader = new(stream); + pStream.Read(reader); ContainerType = pStream.FMTID0.ToString("B").ToUpperInvariant() switch { @@ -222,8 +225,8 @@ public void Save(CFStream cfStream) //throw new NotImplementedException("API Unstable - Work in progress - Milestone 2.3.0.0"); //properties.Sort((a, b) => a.PropertyIdentifier.CompareTo(b.PropertyIdentifier)); - Stream s = new StreamDecorator(cfStream); - BinaryWriter bw = new BinaryWriter(s); + using StreamDecorator s = new(cfStream); + using BinaryWriter bw = new BinaryWriter(s); Guid fmtId0 = FmtID0 ?? (ContainerType == ContainerType.SummaryInfo ? new Guid(WellKnownFMTID.FMTID_SummaryInformation) : new Guid(WellKnownFMTID.FMTID_DocSummaryInformation));