Files
csharpcode/omegapro/PowerTools/Cmdlets/GetOpenXmlCommentCmdlet.cs
2025-08-02 05:20:17 +07:00

40 lines
1.3 KiB
C#

/***************************************************************************
Copyright (c) Microsoft Corporation 2011.
This code is licensed using the Microsoft Public License (Ms-PL). The text of the license can be found here:
http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
***************************************************************************/
using System;
using System.Management.Automation;
namespace OpenXmlPowerTools.Commands
{
[Cmdlet(VerbsCommon.Get, "OpenXmlComment")]
public class GetOpenXmlCommentCmdlet : PowerToolsReadOnlyCmdlet
{
#region Cmdlet Overrides
protected override void ProcessRecord()
{
foreach (var document in AllDocuments("Get-OpenXmlComment"))
{
try
{
if (!(document is WmlDocument))
throw new PowerToolsDocumentException("Not a wordprocessing document.");
object comments = CommentAccessor.GetAllComments((WmlDocument)document, CommentFormat.Xml);
WriteObject(comments, true);
}
catch (Exception e)
{
WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
}
}
}
#endregion
}
}