Example #1
0
        /// <summary>
        /// Initializes a new instance of the FileHeader class.
        /// </summary>
        /// <param name="headerText">
        /// The header text.
        /// </param>
        /// <param name="tokens">
        /// The collection of tokens in the header.
        /// </param>
        /// <param name="parent">
        /// The parent of the header.
        /// </param>
        internal FileHeader(string headerText, CsTokenList tokens, Reference <ICodePart> parent)
        {
            Param.AssertNotNull(headerText, "headerText");
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(parent, "parent");

            this.headerText = headerText;
            this.tokens     = tokens;
            this.parent     = parent;

            this.location = this.tokens.First != null?CsToken.JoinLocations(this.tokens.First, this.tokens.Last) : CodeLocation.Empty;

            // Attempt to load this into an Xml document.
            try
            {
                if (this.headerText.Length > 0)
                {
                    this.headerXml = string.Format(CultureInfo.InvariantCulture, "<root>{0}</root>", HtmlEncode(this.headerText));

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(this.headerXml);

                    // Check whether the header has the autogenerated tag.
                    if (doc.DocumentElement != null)
                    {
                        XmlNode node = doc.DocumentElement["autogenerated"];
                        if (node != null)
                        {
                            // Set this as generated code.
                            this.generated = true;
                        }
                        else
                        {
                            node = doc.DocumentElement["auto-generated"];
                            if (node != null)
                            {
                                // Set this as generated code.
                                this.generated = true;
                            }
                        }

                        StringCollection unstyledElements = new StringCollection();
                        unstyledElements.AddRange(new[] { "unstyled", "stylecopoff", "nostyle" });

                        XmlNodeList childNodes = doc.DocumentElement.ChildNodes;
                        if (childNodes.Cast <XmlNode>().Any(xmlNode => unstyledElements.Contains(xmlNode.Name.ToLowerInvariant())))
                        {
                            this.UnStyled = true;
                        }
                    }
                }
            }
            catch (XmlException)
            {
            }
        }
Example #2
0
        /////// <summary>
        /////// Joins the locations of the two tokens.
        /////// </summary>
        /////// <param name="token1">The first token.</param>
        /////// <param name="token2">The second token.</param>
        /////// <returns>Returns the joined locations.</returns>
        ////internal static CodeLocation JoinLocations(Node<CsToken> token1, CsToken token2)
        ////{
        ////    Param.Ignore(token1, token2);
        ////    return CsToken.JoinLocations(token1 == null ? null : token1.Value, token2);
        ////}

        /////// <summary>
        /////// Joins the locations of the two tokens.
        /////// </summary>
        /////// <param name="token1">The first token.</param>
        /////// <param name="token2">The second token.</param>
        /////// <returns>Returns the joined locations.</returns>
        ////internal static CodeLocation JoinLocations(CsToken token1, Node<CsToken> token2)
        ////{
        ////    Param.Ignore(token1, token2);
        ////    return CsToken.JoinLocations(token1, token2 == null ? null : token2.Value);
        ////}

        /// <summary>
        /// Joins the locations of the two tokens.
        /// </summary>
        /// <param name="token1">
        /// The first token.
        /// </param>
        /// <param name="token2">
        /// The second token.
        /// </param>
        /// <returns>
        /// Returns the joined locations.
        /// </returns>
        internal static CodeLocation JoinLocations(Node <CsToken> token1, Node <CsToken> token2)
        {
            Param.Ignore(token1, token2);
            return(CsToken.JoinLocations(token1 == null ? null : token1.Value, token2 == null ? null : token2.Value));
        }