From d61e97ab421bda789e5d8ec38986a47c625cd7d9 Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Fri, 6 Dec 2024 12:40:03 +1300 Subject: [PATCH] Validate CreateInMemory parameters --- OpenMcdf/RootStorage.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OpenMcdf/RootStorage.cs b/OpenMcdf/RootStorage.cs index 8ded764..e567036 100644 --- a/OpenMcdf/RootStorage.cs +++ b/OpenMcdf/RootStorage.cs @@ -39,7 +39,7 @@ private static void ThrowIfInvalid(FileAccess access) private static void ThrowIfLeaveOpen(StorageModeFlags flags) { if (flags.HasFlag(StorageModeFlags.LeaveOpen)) - throw new ArgumentException($"{StorageModeFlags.LeaveOpen} is not valid for files"); + throw new ArgumentException($"{StorageModeFlags.LeaveOpen} is only valid for injected streams."); } private static IOContextFlags ToIOContextFlags(StorageModeFlags flags) @@ -78,7 +78,12 @@ public static RootStorage Create(Stream stream, Version version = Version.V3, St return new RootStorage(rootContextSite, flags); } - public static RootStorage CreateInMemory(Version version = Version.V3, StorageModeFlags flags = StorageModeFlags.None) => Create(new MemoryStream(), version, flags); + public static RootStorage CreateInMemory(Version version = Version.V3, StorageModeFlags flags = StorageModeFlags.None) + { + ThrowIfLeaveOpen(flags); + + return Create(new MemoryStream(), version, flags); + } public static RootStorage Open(string fileName, FileMode mode, StorageModeFlags flags = StorageModeFlags.None) {