Inheritance: DocumentVisitor
        /// <summary>
        /// Converts any fields of the specified type found in the descendants of the node into static text.
        /// </summary>
        /// <param name="compositeNode">The node in which all descendants of the specified FieldType will be converted to static text.</param>
        /// <param name="targetFieldType">The FieldType of the field to convert to static text.</param>
        public static void ConvertFieldsToStaticText(CompositeNode compositeNode, FieldType targetFieldType)
        {
            string originalNodeText = compositeNode.ToString(SaveFormat.Text); //ExSkip
            FieldsHelper helper = new FieldsHelper(targetFieldType);
            compositeNode.Accept(helper);

            Debug.Assert(originalNodeText.Equals(compositeNode.ToString(SaveFormat.Text)), "Error: Text of the node converted differs from the original"); //ExSkip
            foreach (Node node in compositeNode.GetChildNodes(NodeType.Any, true)) //ExSkip
                Debug.Assert(!(node is FieldChar && ((FieldChar)node).FieldType.Equals(targetFieldType)), "Error: A field node that should be removed still remains."); //ExSkip         
        }
        /// <summary>
        /// Converts any fields of the specified type found in the descendants of the node into static text.
        /// </summary>
        /// <param name="compositeNode">The node in which all descendants of the specified FieldType will be converted to static text.</param>
        /// <param name="targetFieldType">The FieldType of the field to convert to static text.</param>
        public static void ConvertFieldsToStaticText(CompositeNode compositeNode, FieldType targetFieldType)
        {
            string originalNodeText = compositeNode.ToString(SaveFormat.Text); // ExSkip
            FieldsHelper helper = new FieldsHelper(targetFieldType);
            compositeNode.Accept(helper);

            Debug.Assert(originalNodeText.Equals(compositeNode.ToString(SaveFormat.Text)), "Error: Text of the node converted differs from the original"); // ExSkip
            foreach (Node node in compositeNode.GetChildNodes(NodeType.Any, true)) // ExSkip
                Debug.Assert(!(node is FieldChar && ((FieldChar)node).FieldType.Equals(targetFieldType)), "Error: A field node that should be removed still remains."); // ExSkip         
        }
        public static void Run()
        {
            //ExStart:ConvertFieldsInDocument
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithFields();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to static text.
            FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            // Save the document with fields transformed to disk.
            doc.Save(dataDir);
            //ExEnd:ConvertFieldsInDocument
            Console.WriteLine("\nConverted fields to static text in the document successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            //ExStart:ConvertFieldsInParagraph
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithFields();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Pass the appropriate parameters to convert all IF fields to static text that are encountered only in the last
            // paragraph of the document.
            FieldsHelper.ConvertFieldsToStaticText(doc.FirstSection.Body.LastParagraph, FieldType.FieldIf);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            // Save the document with fields transformed to disk.
            doc.Save(dataDir);
            //ExEnd:ConvertFieldsInParagraph
            Console.WriteLine("\nConverted fields to static text in the paragraph successfully.\nFile saved at " + dataDir);
        }