-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a helper function to add user defined properties to the user defined properties container. #190
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,52 @@ public void AddProperty(OLEProperty property) | |
properties.Add(property); | ||
} | ||
|
||
/// <summary> | ||
/// Create a new UserDefinedProperty. | ||
/// </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.</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) | ||
{ | ||
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))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not actually sure if the uniqueness of the user defined property names needs to consider locales / cultures here? |
||
{ | ||
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; | ||
|
||
if (this.PropertyNames.Count > 0) | ||
{ | ||
uint highestIdentifier = this.PropertyNames.Keys.Max(); | ||
identifier = Math.Max(highestIdentifier, 2) + 1; | ||
} | ||
|
||
this.PropertyNames[identifier] = name; | ||
|
||
var op = new OLEProperty(this) | ||
{ | ||
VTType = vtPropertyType, | ||
PropertyIdentifier = identifier | ||
}; | ||
|
||
properties.Add(op); | ||
|
||
return op; | ||
} | ||
|
||
public void RemoveProperty(uint propertyIdentifier) | ||
{ | ||
//throw new NotImplementedException("API Unstable - Work in progress - Milestone 2.3.0.0"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it could be done so that calls against a DocumentSummaryInfo container forward on to the contained UserDefinedProperties container. (Now that there is a CreateUserDefinedProperties() function, it could even create the UserDefinedProperties container if there isn't one already)