示例#1
0
        protected string GetDescription(Type service)
        {
            var description = service.GetCustomAttribute <DescriptionAttribute>()?.Description;

            if (string.IsNullOrEmpty(description))
            {
                XmlElement documentation = DocsByReflection.XMLFromType(service);
                description = documentation?["summary"]?.InnerText.Trim();
                if (string.IsNullOrEmpty(description))
                {
                    description = service.Name.ToFriendlyName();
                }
            }

            return(description);
        }
示例#2
0
        public void RenderSitemap()
        {
            TemplatePlugin.current = new Template(Resources <Sitemap> .Read["handlers.Sitemap.html"]);

            foreach (var routeGroup in RouteTable.Routes.GroupBy(x => ((MethodInfo)((Route)x).DataTokens["methodInfo"]).DeclaringType.ToString()))
            {
                TemplatePlugin.current.Append("links", "<h3 style=\"margin-bottom:0; background:#eee; padding-bottom:0; padding-left:10px; \">" + routeGroup.Key + "</h3>");

                try
                {
                    XmlElement documentation = DocsByReflection.XMLFromType(((MethodInfo)((Route)routeGroup.FirstOrDefault()).DataTokens["methodInfo"]).DeclaringType);
                    TemplatePlugin.current.Append("links", " " + documentation["summary"] == null ? "" : documentation["summary"].InnerText.Trim() + "<br><br>");
                }
                catch (Exception e) {
                    TemplatePlugin.current.Append("links", "<br>");
                }


                foreach (Route route in routeGroup)
                {
                    var    methodInfo = ((MethodInfo)route.DataTokens["methodInfo"]);
                    string summary    = "";
                    try
                    {
                        XmlElement documentation = DocsByReflection.XMLFromMember(((MethodInfo)route.DataTokens["methodInfo"]));
                        summary = documentation["summary"] == null ? "" : documentation["summary"].InnerText.Trim();
                    }
                    catch (Exception e)
                    {
                        //summary = "no description found: " + e.Message;
                    }

                    TemplatePlugin.current.Append("links", "<div style=\"padding-left:10px; margin-left:10px; border-left:5px solid #ccc;\"><a href='./meta?url=" + route.Url.ToURL().Trim().Else("/") + "'>" + route.Url.Trim().Else("/") + "</a>\t\t" +
                                                  "<b>" + methodInfo.Name + "</b>(" +
                                                  string.Join(",", methodInfo.GetParameters().Select(x => "<i>" + x.ParameterType.ToString() + "</i> <b>" + x.Name + "</b>" + (x.IsOptional ? " = " + x.DefaultValue : "")).ToArray())
                                                  + ") returns <i>" + methodInfo.ReturnType.ToString() + "</i><p style=\"color:#999; font-size:smaller; margin-top:0;\">" + summary + "</p></div>");
                }
            }
        }