File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
sources/OpenMcdf.Extensions/OLEProperties Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -180,19 +180,24 @@ public void AddProperty(OLEProperty property)
180
180
/// </summary>
181
181
/// <param name="vtPropertyType">The type of property to create.</param>
182
182
/// <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>
184
186
public OLEProperty AddUserDefinedProperty ( VTPropertyType vtPropertyType , string name )
185
187
{
188
+ // @@TBD@@ If this is a DocumentSummaryInfo container, we could forward the add on to that.
186
189
if ( this . ContainerType != ContainerType . UserDefinedProperties )
187
- return null ;
190
+ {
191
+ throw new InvalidOperationException ( $ "UserDefinedProperties are not allowed in containers of type { this . ContainerType } ") ;
192
+ }
188
193
189
194
// As per https://learn.microsoft.com/en-us/openspecs/windows_protocols/MS-OLEPS/4177a4bc-5547-49fe-a4d9-4767350fd9cf
190
195
// the property names have to be unique, and are case insensitive.
191
196
if ( this . PropertyNames . Any ( property => property . Value . Equals ( name , StringComparison . InvariantCultureIgnoreCase ) ) )
192
197
{
193
198
throw new ArgumentException ( $ "User defined property names must be unique and { name } already exists", nameof ( name ) ) ;
194
199
}
195
-
200
+
196
201
// Work out a property identifier - must be > 1 and unique as per
197
202
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-oleps/333959a3-a999-4eca-8627-48a224e63e77
198
203
uint identifier = 2 ;
You can’t perform that action at this time.
0 commit comments