From 0cdb88718a2ceeaab23ec174e36fab0eebd18c1e Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 13 Oct 2024 15:40:04 +0100 Subject: [PATCH] Tweak error handling --- .../OLEProperties/OLEPropertiesContainer.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs b/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs index 351ea90..a055847 100644 --- a/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs +++ b/sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs @@ -180,11 +180,16 @@ public void AddProperty(OLEProperty property) /// /// The type of property to create. /// The name of the new property. - /// The new property, of null if this container can't contain user defined properties. + /// The new property. + /// If UserDefinedProperties aren't allowed for this container. + /// If a property with the name already exists."/> public OLEProperty AddUserDefinedProperty(VTPropertyType vtPropertyType, string name) { + // @@TBD@@ If this is a DocumentSummaryInfo container, we could forward the add on to that. if (this.ContainerType != ContainerType.UserDefinedProperties) - return null; + { + throw new InvalidOperationException($"UserDefinedProperties are not allowed in containers of type {this.ContainerType}"); + } // As per https://learn.microsoft.com/en-us/openspecs/windows_protocols/MS-OLEPS/4177a4bc-5547-49fe-a4d9-4767350fd9cf // the property names have to be unique, and are case insensitive. @@ -192,7 +197,7 @@ public OLEProperty AddUserDefinedProperty(VTPropertyType vtPropertyType, string { throw new ArgumentException($"User defined property names must be unique and {name} already exists", nameof(name)); } - + // Work out a property identifier - must be > 1 and unique as per // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-oleps/333959a3-a999-4eca-8627-48a224e63e77 uint identifier = 2;