Пример #1
0
 /// <summary>
 /// Write as C# code.
 /// </summary>
 private static void WriteAsCode(XText text, CommentSection section, bool inCode)
 {
     var lineNo = 0;
     var content = text.Value;
     if (string.IsNullOrEmpty(content))
         return;
     foreach (var part in content.Split('\n'))
     {
         if ((lineNo > 0) && inCode)
             section.WriteLine();
         section.Write(part.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;"));
         lineNo++;
     }
 }
Пример #2
0
        /// <summary>
        /// Write as C# code.
        /// </summary>
        private static void WriteAsCode(XText text, CommentSection section, bool inCode)
        {
            var lineNo  = 0;
            var content = text.Value;

            if (string.IsNullOrEmpty(content))
            {
                return;
            }
            foreach (var part in content.Split('\n'))
            {
                if ((lineNo > 0) && inCode)
                {
                    section.WriteLine();
                }
                section.Write(part.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;"));
                lineNo++;
            }
        }
Пример #3
0
        /// <summary>
        /// Write as C# code.
        /// </summary>
        private void WriteAsCode(XElement element, CommentBuilder builder, CommentSection section, bool inCode, IDocTypeNameResolver resolver)
        {
            string tag = null;
            string postfix = null;
            var appendNewline = false;

            if (IsEmpty(element))
                return;

            switch (element.Name.LocalName)
            {
                case "para":
                    tag = "para";
                    break;
                case "ref":
                    var id = element.GetAttribute("refid");
                    DocClass @class;
                    string name = null;
                    if (model.TryGetClassById(id, out @class))
                    {
                        name = resolver.ResolveTypeName(@class.Name);
                    }
                    if (name != null)
                    {
                        section.Write("<see cref=\"{0}\">", name);
                        postfix = "</see>";
                    } 
                    break;
                case "heading":
                    var level = element.GetAttribute("level");
                    tag = "h" + level;
                    break;
                case "preformatted":
                    tag = "pre";
                    inCode = true;
                    break;
                case "itemizedlist":
                    tag = "ul";
                    break;
                case "orderedlist":
                    tag = "ol";
                    break;
                case "listitem":
                    tag = "li";
                    break;
                case "linebreak":
                    tag = "br";
                    break;
                case "bold":
                case "emphasis":
                    tag = "b";
                    break;
                case "computeroutput":
                    tag = "code";
                    break;
                case "programlisting":
                    if (!inCode) tag = "c";
                    break;
                case "codeline":
                    if (inCode) appendNewline = true;
                    break;
                case "table":
                    tag = "table";
                    break;
                case "superscript":
                case "verbatim":
                    tag = "span";
                    break;
                case "simplesect":
                    var kind = element.GetAttribute("kind");
                    if (kind == "return") section = builder.Returns;
                    break;
                case "nonbreakablespace":
                case "sp":
                    section.Write(" ");
                    return;
                case "mdash":
                case "ndash":
                case "ulink":
                case "parameterlist":
                case "variablelist":
                case "anchor":
                    return;
                case "highlight":
                    break;
                default:
                    tag = element.Name.LocalName;
                    break;
            }

            if (tag != null)
            {
                section.Write("<{0}>", tag);
            }

            foreach (var child in element.Nodes())
            {
                WriteAsCode(child, builder, section, inCode, resolver);
            }

            if (tag != null)
            {
                section.Write("</{0}>", tag);
            }
            if (postfix != null)
            {
                section.Write("{0}", postfix);
            }
            if (appendNewline)
            {
                section.WriteLine();
            }
        }
Пример #4
0
        /// <summary>
        /// Write as C# code.
        /// </summary>
        private void WriteAsCode(XElement element, CommentBuilder builder, CommentSection section, bool inCode, IDocTypeNameResolver resolver)
        {
            string tag           = null;
            string postfix       = null;
            var    appendNewline = false;

            if (IsEmpty(element))
            {
                return;
            }

            switch (element.Name.LocalName)
            {
            case "para":
                tag = "para";
                break;

            case "ref":
                var      id = element.GetAttribute("refid");
                DocClass @class;
                string   name = null;
                if (model.TryGetClassById(id, out @class))
                {
                    name = resolver.ResolveTypeName(@class.Name);
                }
                if (name != null)
                {
                    section.Write("<see cref=\"{0}\">", name);
                    postfix = "</see>";
                }
                break;

            case "heading":
                var level = element.GetAttribute("level");
                tag = "h" + level;
                break;

            case "preformatted":
                tag    = "pre";
                inCode = true;
                break;

            case "itemizedlist":
                tag = "ul";
                break;

            case "orderedlist":
                tag = "ol";
                break;

            case "listitem":
                tag = "li";
                break;

            case "linebreak":
                tag = "br";
                break;

            case "bold":
            case "emphasis":
                tag = "b";
                break;

            case "computeroutput":
                tag = "code";
                break;

            case "programlisting":
                if (!inCode)
                {
                    tag = "c";
                }
                break;

            case "codeline":
                if (inCode)
                {
                    appendNewline = true;
                }
                break;

            case "table":
                tag = "table";
                break;

            case "superscript":
            case "verbatim":
                tag = "span";
                break;

            case "simplesect":
                var kind = element.GetAttribute("kind");
                if (kind == "return")
                {
                    section = builder.Returns;
                }
                break;

            case "nonbreakablespace":
            case "sp":
                section.Write(" ");
                return;

            case "mdash":
            case "ndash":
            case "ulink":
            case "parameterlist":
            case "variablelist":
            case "anchor":
                return;

            case "highlight":
                break;

            default:
                tag = element.Name.LocalName;
                break;
            }

            if (tag != null)
            {
                section.Write("<{0}>", tag);
            }

            foreach (var child in element.Nodes())
            {
                WriteAsCode(child, builder, section, inCode, resolver);
            }

            if (tag != null)
            {
                section.Write("</{0}>", tag);
            }
            if (postfix != null)
            {
                section.Write("{0}", postfix);
            }
            if (appendNewline)
            {
                section.WriteLine();
            }
        }