Represents an empty XML element.
Inheritance: MSBuildProjectTools.LanguageServer.SemanticModel.XSElement
Esempio n. 1
0
            /// <summary>
            ///     Visit an <see cref="XmlEmptyElementSyntax"/>.
            /// </summary>
            /// <param name="emptyElement">
            ///     The <see cref="XmlEmptyElementSyntax"/>.
            /// </param>
            /// <returns>
            ///     The <see cref="XmlEmptyElementSyntax"/> (unchanged).
            /// </returns>
            public override SyntaxNode VisitXmlEmptyElement(XmlEmptyElementSyntax emptyElement)
            {
                Range elementRange    = emptyElement.Span.ToNative(_textPositions);
                Range nameRange       = emptyElement.NameNode?.Span.ToNative(_textPositions) ?? elementRange;
                Range attributesRange = emptyElement.AttributesNode?.FullSpan.ToNative(_textPositions) ?? elementRange;

                XSElement xsElement;

                if (String.IsNullOrWhiteSpace(emptyElement.Name))
                {
                    xsElement = new XSInvalidElement(emptyElement, elementRange, nameRange, attributesRange, parent: CurrentElement, hasContent: false);
                }
                else
                {
                    xsElement = new XSEmptyElement(emptyElement, elementRange, nameRange, attributesRange, parent: CurrentElement);
                }

                if (xsElement.ParentElement is XSElementWithContent parentElement)
                {
                    parentElement.Content = parentElement.Content.Add(xsElement);
                }

                PushElement(xsElement);

                foreach (XmlAttributeSyntax attribute in emptyElement.AsSyntaxElement.Attributes)
                {
                    Visit(attribute);
                }

                PopElement();

                return(emptyElement);
            }
Esempio n. 2
0
        /// <summary>
        ///     Does the location represent an empty element?
        /// </summary>
        /// <param name="location">
        ///     The XML location.
        /// </param>
        /// <param name="emptyElement">
        ///     Receives the <see cref="XSEmptyElement"/>.
        /// </param>
        /// <returns>
        ///     <c>true</c>, if the location represents an empty element; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsEmptyElement(this XmlLocation location, out XSEmptyElement emptyElement)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            if (!location.IsEmptyElement())
            {
                emptyElement = null;

                return(false);
            }
            else
            {
                emptyElement = (XSEmptyElement)location.Node;

                return(true);
            }
        }