예제 #1
0
 public StylerService(IStylerOptions options, XamlLanguageOptions xamlLanguageOptions)
 {
     this.xmlEscapingService          = new XmlEscapingService();
     this.documentManipulationService = new DocumentManipulationService(options);
     this.options             = options;
     this.xamlLanguageOptions = xamlLanguageOptions;
 }
        /// <summary>
        /// Single line value line in style as:
        /// attribute_name="attribute_value"
        /// </summary>
        /// <param name="attrInfo"></param>
        /// <returns></returns>
        public string ToSingleLineString(AttributeInfo attrInfo, XamlLanguageOptions xamlLanguageOptions)
        {
            var valuePart = attrInfo.IsMarkupExtension
                ? this.formatter.FormatSingleLine(attrInfo.MarkupExtension)
                : attrInfo.Value.ToXmlEncodedString(xamlLanguageOptions.UnescapedAttributeCharacters);

            return($"{attrInfo.Name}=\"{valuePart}\"");
        }
예제 #3
0
 public ElementDocumentProcessor(
     IStylerOptions options,
     XamlLanguageOptions xamlLanguageOptions,
     AttributeInfoFactory attributeInfoFactory,
     AttributeInfoFormatter attributeInfoFormatter,
     IndentService indentService,
     XmlEscapingService xmlEscapingService)
 {
     this.options                = options;
     this.xamlLanguageOptions    = xamlLanguageOptions;
     this.attributeInfoFactory   = attributeInfoFactory;
     this.attributeInfoFormatter = attributeInfoFormatter;
     this.indentService          = indentService;
     this.xmlEscapingService     = xmlEscapingService;
     this.noNewLineElementsList  = options.NoNewLineElements.ToList();
     this.firstLineAttributes    = options.FirstLineAttributes.ToList();
 }
        public static XamlLanguageOptions GetXamlLanguageOptions(this Document document)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var options = new XamlLanguageOptions();

            if (document == null || document.ReadOnly)
            {
                return(options);
            }

            if (document.IsAvaloniaXaml())
            {
                options.IsFormatable = true;
                options.UnescapedAttributeCharacters.Add('>');

                return(options);
            }

            options.IsFormatable = document.IsXaml() || document.IsXamarinXaml();

            return(options);
        }
예제 #5
0
        private static Func <Action> SetupFormatDocumentContinuation(Document document, IStylerOptions stylerOptions, XamlLanguageOptions xamlLanguageOptions)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var       textDocument = (TextDocument)document.Object("TextDocument");
            EditPoint startPoint   = textDocument.StartPoint.CreateEditPoint();
            EditPoint endPoint     = textDocument.EndPoint.CreateEditPoint();
            string    xamlSource   = startPoint.GetText(endPoint);

            return(() =>
            {
                // This part can be executed in parallel.
                var styler = new StylerService(stylerOptions, xamlLanguageOptions);
                xamlSource = styler.StyleDocument(xamlSource);

                return () =>
                {
                    // This part should be executed sequentially.
                    ThreadHelper.ThrowIfNotOnUIThread();
                    startPoint.ReplaceText(endPoint, xamlSource, (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
                };
            });
        }