VisitCommentRangeEnd
محتويات
[
يخفي
]DocumentVisitor.VisitCommentRangeEnd method
يتم استدعاؤها عند مواجهة نهاية نطاق التعليق النصي.
public virtual VisitorAction VisitCommentRangeEnd(CommentRangeEnd commentRangeEnd)
معامل | يكتب | وصف |
---|---|---|
commentRangeEnd | CommentRangeEnd | الشيء الذي يتم زيارته. |
قيمة الإرجاع
أVisitorAction
القيمة التي تحدد كيفية مواصلة التعداد.
أمثلة
يوضح كيفية طباعة بنية العقدة لكل تعليق ونطاق التعليق في مستند.
public void CommentsToText()
{
Document doc = new Document(MyDir + "DocumentVisitor-compatible features.docx");
CommentStructurePrinter visitor = new CommentStructurePrinter();
// عندما نحصل على عقدة مركبة لقبول زائر مستند، يقوم الزائر بزيارة العقدة المستقبلة،
// ثم يمر عبر جميع أبناء العقدة بطريقة العمق أولاً.
//يمكن للزائر قراءة وتعديل كل عقدة تمت زيارتها.
doc.Accept(visitor);
Console.WriteLine(visitor.GetText());
}
/// <summary>
/// يجتاز شجرة العقد غير الثنائية المكونة من عقد فرعية.
/// إنشاء خريطة في شكل سلسلة من جميع عقد Comment/CommentRange التي تم مواجهتها وأطفالها.
/// </summary>
public class CommentStructurePrinter : DocumentVisitor
{
public CommentStructurePrinter()
{
mBuilder = new StringBuilder();
mVisitorIsInsideComment = false;
}
public string GetText()
{
return mBuilder.ToString();
}
/// <summary>
/// يتم استدعاؤها عند مواجهة عقدة تشغيل في المستند.
/// سيتم تسجيل التشغيل فقط إذا كان فرعيًا لعقدة تعليق أو تعليق نطاق.
/// </summary>
public override VisitorAction VisitRun(Run run)
{
if (mVisitorIsInsideComment) IndentAndAppendLine("[Run] \"" + run.GetText() + "\"");
return VisitorAction.Continue;
}
/// <summary>
/// يتم استدعاؤها عند مواجهة عقدة CommentRangeStart في المستند.
/// </summary>
public override VisitorAction VisitCommentRangeStart(CommentRangeStart commentRangeStart)
{
IndentAndAppendLine("[Comment range start] ID: " + commentRangeStart.Id);
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.Continue;
}
/// <summary>
/// يتم استدعاؤها عند مواجهة عقدة CommentRangeEnd في المستند.
/// </summary>
public override VisitorAction VisitCommentRangeEnd(CommentRangeEnd commentRangeEnd)
{
mDocTraversalDepth--;
IndentAndAppendLine("[Comment range end]");
mVisitorIsInsideComment = false;
return VisitorAction.Continue;
}
/// <summary>
/// يتم استدعاؤها عند مواجهة عقدة تعليق في المستند.
/// </summary>
public override VisitorAction VisitCommentStart(Comment comment)
{
IndentAndAppendLine(
$"[Comment start] For comment range ID {comment.Id}, By {comment.Author} on {comment.DateTime}");
mDocTraversalDepth++;
mVisitorIsInsideComment = true;
return VisitorAction.Continue;
}
/// <summary>
/// يتم استدعاؤها بعد زيارة جميع العقد الفرعية لعقدة التعليق.
/// </summary>
public override VisitorAction VisitCommentEnd(Comment comment)
{
mDocTraversalDepth--;
IndentAndAppendLine("[Comment end]");
mVisitorIsInsideComment = false;
return VisitorAction.Continue;
}
/// <summary>
/// أضف سطرًا إلى StringBuilder، وقم بتدويره حسب عمق الزائر
/// في شجرة التعليق/نطاق التعليق للعقد الفرعية.
/// </summary>
/// <اسم المعلمة="نص"></param>
private void IndentAndAppendLine(string text)
{
for (int i = 0; i < mDocTraversalDepth; i++)
{
mBuilder.Append("| ");
}
mBuilder.AppendLine(text);
}
private bool mVisitorIsInsideComment;
private int mDocTraversalDepth;
private readonly StringBuilder mBuilder;
}
أنظر أيضا
- enum VisitorAction
- class CommentRangeEnd
- class DocumentVisitor
- مساحة الاسم Aspose.Words
- المجسم Aspose.Words