feat: add DocumentProperties option for setting document metadata#78
feat: add DocumentProperties option for setting document metadata#78
Conversation
Add ability to set Author, Title, Subject, Description, Keywords, Category, and LastModifiedBy on output documents via PlaceholderReplacementOptions.DocumentProperties.
Make ApplyDocumentProperties static, add null-origin test case, and document the DocumentProperties feature in README, Examples, and quick-start guide.
There was a problem hiding this comment.
Pull request overview
This pull request adds support for setting document metadata properties (Author, Title, Subject, Description, Keywords, Category, LastModifiedBy) when processing Word templates. The feature allows consumers to override or set document properties programmatically while preserving original template values for properties left as null.
Changes:
- Added
DocumentPropertiesclass with 7 metadata fields as nullable, init-only properties - Extended
PlaceholderReplacementOptionswith optionalDocumentPropertiesparameter - Implemented
ApplyDocumentPropertiesmethod inDocumentTemplateProcessoras a post-processing step
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| TriasDev.Templify/Core/DocumentProperties.cs | New sealed class defining 7 document metadata properties with XML documentation |
| TriasDev.Templify/Core/PlaceholderReplacementOptions.cs | Added nullable DocumentProperties property to configuration options |
| TriasDev.Templify/Core/DocumentTemplateProcessor.cs | Added ApplyDocumentProperties method that maps properties to OPC PackageProperties |
| TriasDev.Templify.Tests/Integration/DocumentPropertiesTests.cs | Comprehensive integration tests covering all scenarios (7 tests) |
| TriasDev.Templify.Tests/Helpers/DocumentBuilder.cs | Added SetAuthor, SetTitle, SetSubject methods for test document setup |
| TriasDev.Templify.Tests/Helpers/DocumentVerifier.cs | Added 7 getter methods for verifying document properties in tests |
| docs/for-developers/quick-start.md | Added documentation section explaining DocumentProperties usage with example |
| TriasDev.Templify/README.md | Added comprehensive documentation with behavior explanation, property mapping table, and examples |
| TriasDev.Templify/Examples.md | Added new section with examples of setting document properties |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```csharp | ||
| var options = new PlaceholderReplacementOptions | ||
| { | ||
| Culture = new CultureInfo("de-DE"), | ||
| UpdateFieldsOnOpen = UpdateFieldsOnOpenMode.Auto, | ||
| DocumentProperties = new DocumentProperties | ||
| { | ||
| Author = "Rechnungssystem", | ||
| Title = $"Rechnung {invoiceNumber}", | ||
| LastModifiedBy = "Templify" | ||
| } | ||
| }; | ||
| ``` |
There was a problem hiding this comment.
The code example is missing the required using System.Globalization; statement for CultureInfo, and the variable invoiceNumber is used in the string interpolation but is not declared or defined anywhere in the example. This would cause compilation errors if a user tries to use this code as-is.
| /// <summary> | ||
| /// Gets or initializes the document metadata properties to set on the output document. | ||
| /// When null (default), the original template properties are preserved unchanged. | ||
| /// Only non-null property values within <see cref="Core.DocumentProperties"/> are applied; |
There was a problem hiding this comment.
The XML documentation comment uses Core.DocumentProperties with a namespace prefix, but since both PlaceholderReplacementOptions and DocumentProperties are in the same TriasDev.Templify.Core namespace, the prefix is unnecessary. For consistency with other references in this file (e.g., line 17 uses MissingVariableBehavior without prefix, line 119 uses PlaceholderReplacementOptions without prefix), it should be just DocumentProperties instead of Core.DocumentProperties.
| /// Only non-null property values within <see cref="Core.DocumentProperties"/> are applied; | |
| /// Only non-null property values within <see cref="DocumentProperties"/> are applied; |
Remove unnecessary namespace prefix in see cref, and add missing using statement and variable declaration in Examples.md code sample.
Summary
DocumentPropertiesclass with 7 metadata fields (Author, Title, Subject, Description, Keywords, Category, LastModifiedBy)DocumentProperties?option toPlaceholderReplacementOptions— null properties preserve original template values, non-null values overwritedocument.PackagePropertiesas a post-processing step inDocumentTemplateProcessorCloses #77
Test plan
dotnet format --verify-no-changesclean