示例#1
0
        /// <summary>
        /// Add the paragraph id feature if not already registered.
        /// </summary>
        /// <param name="doc">Document to add feature to.</param>
        /// <param name="options">Options of how paragraph ids should be generated.</param>
        public static void AddParagraphIdFeature(this WordprocessingDocument doc, ParagraphIdOptions?options = default)
        {
            options ??= new();

            doc.AddParagraphIdGeneratorFeature();

            if (doc.Features.Get <IParagraphIdCollectionFeature>() is null)
            {
                doc.AddPartEventsFeature();
                doc.AddElementEventFeature();

                var feature = new WordDocumentParagraphIdCollectionFeature(
                    doc,
                    options,
                    doc.Features.GetRequired <IPartEventsFeature>(),
                    doc.Features.GetRequired <IElementEventFeature>());

                doc.Features.SetDisposable <IParagraphIdCollectionFeature>(feature);

                feature.Initialize();
            }
        }