Skip to content

Commit

Permalink
Tweak error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Oct 14, 2024
1 parent a462c09 commit 0cdb887
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,24 @@ public void AddProperty(OLEProperty property)
/// </summary>
/// <param name="vtPropertyType">The type of property to create.</param>
/// <param name="name">The name of the new property.</param>
/// <returns>The new property, of null if this container can't contain user defined properties.</returns>
/// <returns>The new property.</returns>
/// <exception cref="InvalidOperationException">If UserDefinedProperties aren't allowed for this container.</exception>
/// <exception cref="ArgumentException">If a property with the name <paramref name="name"/> already exists."/></exception>
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.
if (this.PropertyNames.Any(property => property.Value.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
{
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;
Expand Down

0 comments on commit 0cdb887

Please sign in to comment.