Search Results for

    Show / Hide Table of Contents

    IMarkupDataVisitor

    The visitor pattern lets you traverse all child objects in a markup hierarchy without depending on the hierarchy's internal implementation. This makes your code easier to maintain when the hierarchy changes.

    Implementing IMarkupDataVisitor

    To use this pattern, implement the IMarkupDataVisitor interface and provide all required visitor methods. In most cases, it also helps to add a private helper method that calls AcceptVisitor() for each child item in a markup container.

    • C#
    private void AppendItems(IAbstractMarkupDataContainer parent)
    {
        foreach (var item in parent)
        {
            item.AcceptVisitor(this);
        }
    }
    

    You can use this helper method to start traversal for all items in a paragraph unit so that your writer can output them to the translated target document. A common place to do this is in ProcessParagraphUnit. There, the IParagraphUnit object can pass its source and target paragraphs to AppendItems(), while the IMarkupDataVisitor methods process the different text and markup objects in the hierarchy.

    Visitor methods

    VisitTagPair()

    VisitTagPair is called when the visitor reaches an ITagPair object. A typical implementation writes the start tag to the target document, processes the child nodes, and then writes the end tag. Some bilingual writers may need to cache this information first. To process the child nodes, call AppendItems() with the tag pair as the parameter.

    VisitPlaceholderTag()

    VisitPlaceholderTag is called when the visitor reaches an IPlaceholderTag object. A typical implementation writes the placeholder tag to the target document, although some bilingual writers may need to cache the information first.

    VisitText()

    VisitText is called when the visitor reaches an IText object. A typical implementation writes the text content to the target document. When you process text items, also consider the ContentRestriction value. In some cases, the restriction indicates that you should write the source text instead of the target text. When that happens for a translatable paragraph unit, call AppendItems() for the source paragraph instead of the target paragraph so that later calls to VisitText() use the source text.

    VisitSegment()

    VisitSegment is called when the visitor reaches an ISegment object. A typical implementation writes any required information from ISegmentPairProperties, such as MatchPercent or TranslationOrigin.

    VisitLocationMarker()

    VisitLocationMarker is called when the visitor reaches an ILocationMarker object. Location markers usually identify a position in a translated document, such as the scroll position in a framework-based preview editor.

    VisitOtherMarker()

    VisitOtherMarker is called when the visitor reaches an IOtherMarker object.

    VisitRevisionMarker()

    VisitRevisionMarker is called when the visitor reaches an IRevisionMarker object. Revision markers usually represent tracked changes.

    VisitLockedContent()

    VisitLockedContent is called when the visitor reaches an ILockedContent container. A typical implementation checks the LockType value in the container's properties to determine how to handle the content when writing the translated target document. In many cases, you then call AppendItems() for the Content collection.

    See also

    • Reference IMarkupDataVisitor
    • Visitor pattern
    • Design patterns
    Note

    This content may be out-of-date. To check the latest information on this topic, inspect the libraries using the Visual Studio Object Browser.

    • Improve this Doc
    In this article
    Back to top Generated by DocFX