Skip to content

Commit 0cdb887

Browse files
committed
Tweak error handling
1 parent a462c09 commit 0cdb887

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,24 @@ public void AddProperty(OLEProperty property)
180180
/// </summary>
181181
/// <param name="vtPropertyType">The type of property to create.</param>
182182
/// <param name="name">The name of the new property.</param>
183-
/// <returns>The new property, of null if this container can't contain user defined properties.</returns>
183+
/// <returns>The new property.</returns>
184+
/// <exception cref="InvalidOperationException">If UserDefinedProperties aren't allowed for this container.</exception>
185+
/// <exception cref="ArgumentException">If a property with the name <paramref name="name"/> already exists."/></exception>
184186
public OLEProperty AddUserDefinedProperty(VTPropertyType vtPropertyType, string name)
185187
{
188+
// @@TBD@@ If this is a DocumentSummaryInfo container, we could forward the add on to that.
186189
if (this.ContainerType != ContainerType.UserDefinedProperties)
187-
return null;
190+
{
191+
throw new InvalidOperationException($"UserDefinedProperties are not allowed in containers of type {this.ContainerType}");
192+
}
188193

189194
// As per https://learn.microsoft.com/en-us/openspecs/windows_protocols/MS-OLEPS/4177a4bc-5547-49fe-a4d9-4767350fd9cf
190195
// the property names have to be unique, and are case insensitive.
191196
if (this.PropertyNames.Any(property => property.Value.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
192197
{
193198
throw new ArgumentException($"User defined property names must be unique and {name} already exists", nameof(name));
194199
}
195-
200+
196201
// Work out a property identifier - must be > 1 and unique as per
197202
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-oleps/333959a3-a999-4eca-8627-48a224e63e77
198203
uint identifier = 2;

0 commit comments

Comments
 (0)