// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
using System.IO;
using GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
    // The actual formatting of a specific content object in an MS Word document
    // is determined by a combination of several factors, such as direct formatting
    // that may be applied to the object, the style associated with the object,
    // as well as direct formatting and styles of the containing objects.
    // This sample demonstrates the use of the GcWordDocument.GetPropertyValueSource()
    // method that allows to find the object that provides the actual current value
    // of a style property (in this sample, the size of a font).
    // This sample uses the document from the SampleParagraphs sample.
    public class GetStyleSource
        public GcWordDocument CreateDocx()
            GcWordDocument doc = new GcWordDocument();
            doc.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx"));

            // Find the object that provides formatting for the first text run in this document:
            object source = GcWordDocument.GetPropertyValueSource(() => doc.Body.Runs.First.Font.Size);

            // Add the info that we found to the document:
            doc.Body.Paragraphs.Add($">>> The object that determines the font size of the first text run in this document is '{source}'.");
            // If the property source is a style, add its name:
            if (source is Style s)
                doc.Body.Paragraphs.Add($">>> The object is the style '{s.WordName}'.");

            return doc;