Ejemplo n.º 1
0
        /// <summary>
        /// Creates the XML open tag string for an XElement.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>The XML open tag. In case of an element without value, the tag is self-closing.</returns>
        private static string CreateXmlOpenTag(XElement element, IXmlTagOptions options)
        {
            var builder = new StringBuilder();
            var name    = element.Name.LocalName;

            builder.Append("<");

            builder.Append(TagCase(name, options.Case));

            if (element.HasAttributes)
            {
                foreach (var attr in element.Attributes())
                {
                    builder.Append(CodeCommentHelper.Spacer);
                    builder.Append(attr);
                }
            }

            if (element.IsEmpty)
            {
                if (options.SpaceSelfClosing)
                {
                    builder.Append(CodeCommentHelper.Spacer);
                }

                builder.Append("/");
            }

            builder.Append(">");

            var result = builder.ToString();

            return(options.KeepTogether ? CodeCommentHelper.SpaceToFake(result) : result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the XML close tag string for an XElement.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>
        /// The XML close tag, or <c>null</c> if the element has no value and is a self-closing tag.
        /// </returns>
        private static string CreateXmlCloseTag(XElement element, IXmlTagOptions options)
        {
            if (element.IsEmpty)
            {
                return(null);
            }

            return($"</{TagCase(element.Name.LocalName, options.Case)}>");
        }
 public XmlTagOptions(FormatterOptionsXmlTag tag, IXmlTagOptions fallback)
 {
     Case             = tag.Case != XmlTagCase.Default ? tag.Case : fallback.Case != XmlTagCase.Default ? fallback.Case : XmlTagCase.Keep;
     Indent           = tag.Indent ?? fallback.Indent;
     KeepTogether     = tag.KeepTogether ?? fallback.KeepTogether;
     Literal          = tag.Literal ?? false;
     SpaceContent     = tag.SpaceContent ?? fallback.SpaceContent;
     SpaceSelfClosing = tag.SpaceSelfClosing ?? fallback.SpaceSelfClosing;
     Split            = tag.Split != XmlTagNewLine.Default ? tag.Split : fallback.Split != XmlTagNewLine.Default ? fallback.Split : XmlTagNewLine.Content;
 }