Beispiel #1
0
        private void ParseMethod(List <IDocumentationMember> members, XmlNode node)
        {
            string     name       = node.Attributes["name"].Value.Substring(2);
            Identifier member     = Identifier.FromString(node.Attributes["name"].Value);
            string     methodName = GetMethodName(name);
            int        index      = members.FindIndex(x => member.Equals(x.Name));

            if (index == -1)
            {
                return;              // TODO: Privates
            }
            if (methodName == "#ctor")
            {
                return;                        // TODO: Fix constructors
            }
            for (int i = 0; i < members.Count; i++)
            {
                var methodMember = members[i] as UndocumentedMethod;

                if (methodMember != null && methodMember.Match(member))
                {
                    members[i] = new DocumentedMethod(member, node, methodMember.Method, methodMember.TargetType);
                }
            }
        }
Beispiel #2
0
        private string GetUrl(DocumentedMethod method)
        {
            var nsRoute     = _service.GetRoutePart(method.Type.Namespace);
            var typeRoute   = _service.GetRoutePart(method.Type);
            var methodRoute = _service.GetRoutePart(method);

            return(string.Concat(nsRoute, "/", typeRoute, "/", methodRoute));
        }
 public void Text_PlotMethods_AllHaveSummaries()
 {
     foreach (MethodInfo info in ScottPlot.Cookbook.Locate.GetPlotMethods())
     {
         var method = new DocumentedMethod(info, LoadedXmlDocument);
         Assert.IsTrue(method.HasXmlDocumentation);
         Assert.IsNotNull(method.Summary);
     }
 }
Beispiel #4
0
 public static IHtmlString MethodLink(this ApiServices context, DocumentedMethod method, MethodRenderOption options)
 {
     if (method != null)
     {
         options = FixOptions(method, options);
         var signature = context.SignatureResolver.GetMethodSignature(method);
         return(context.SignatureRenderer.Render(signature, MethodRenderOption.Link | options));
     }
     return(MvcHtmlString.Empty);
 }
Beispiel #5
0
        public static IHtmlString BreadCrumb(this ApiServices context, DocumentedMethod method)
        {
            var breadcrumb = new Breadcrumb();

            breadcrumb.AppendApiRoot();
            breadcrumb.AppendNamespaces(context, method.Type.Namespace, true);
            breadcrumb.AppendType(context, method.Type, true);
            breadcrumb.AppendMethod(context, method);
            return(breadcrumb.Render());
        }
Beispiel #6
0
        public void Add(List <Namespace> namespaces, DocumentedMethod association)
        {
            if (association.Method == null)
            {
                return;
            }

            var ns   = FindNamespace(association, namespaces);
            var type = FindType(ns, association);

            try {
                var methodReturnType = DeclaredType.Unresolved(
                    Identifier.FromType(association.Method.ReturnType),
                    association.Method.ReturnType,
                    Namespace.Unresolved(Identifier.FromNamespace(association.Method.ReturnType.Namespace)));
                var doc = Method.Unresolved(
                    Identifier.FromMethod(association.Method, association.TargetType),
                    type, association.Method, methodReturnType);

                ParseSummary(association, doc);
                ParseRemarks(association, doc);
                ParseValue(association, doc);
                ParseReturns(association, doc);
                ParseExample(association, doc);

                foreach (var parameter in association.Method.GetParameters())
                {
                    var reference = DeclaredType.Unresolved(
                        Identifier.FromType(parameter.ParameterType),
                        parameter.ParameterType,
                        Namespace.Unresolved(Identifier.FromNamespace(parameter.ParameterType.Namespace)));
                    var docParam = new MethodParameter(parameter.Name, reference);

                    ParseParamSummary(association, docParam);

                    doc.AddParameter(docParam);
                }

                if (matchedAssociations.ContainsKey(association.Name))
                {
                    return;                     // weird case when a type has the same method declared twice
                }
                matchedAssociations.Add(association.Name, doc);
                if (type == null)
                {
                    return;
                }
                type.AddMethod(doc);
            } catch (IOException ex) {
                var doc = Method.Unresolved(
                    Identifier.FromMethod(association.Method, association.TargetType),
                    type, association.Method, new NullReference());
                type.AddMethod(doc);
            }
        }
Beispiel #7
0
        public IEncodedString DslType(DocumentedMethod method)
        {
            bool isPropertyAlias;

            if (method.IsCakeAlias(out isPropertyAlias))
            {
                return(isPropertyAlias
                    ? new HtmlEncodedString("Property")
                    : new HtmlEncodedString("Method"));
            }
            throw new InvalidOperationException("Unknown DSL alias type.");
        }
Beispiel #8
0
        public MethodSignature GetMethodSignature(DocumentedMethod method)
        {
            MethodSignature signature;

            if (_documentedMethods.TryGetValue(method, out signature))
            {
                return(signature);
            }
            var message = $"Could not find signature for {method.Identity}.";

            throw new InvalidOperationException(message);
        }
Beispiel #9
0
        public static IHtmlString MethodName(this ApiServices context, DocumentedMethod method)
        {
            if (method != null)
            {
                var options = MethodRenderOption.Name | MethodRenderOption.Parameters;
                options = FixOptions(method, options);

                var signature = context.SignatureResolver.GetMethodSignature(method);
                return(context.SignatureRenderer.Render(signature, MethodRenderOption.Name | MethodRenderOption.Parameters));
            }
            return(MvcHtmlString.Empty);
        }
Beispiel #10
0
        protected string OneLineInfo(DocumentedMethod method, string baseUrl)
        {
            string        url = Sanitize(method.Name);
            StringBuilder sb  = new StringBuilder();

            sb.Append($"<a href='{baseUrl}#{url}'><strong>{method.Name}()</strong></a>");
            if (!string.IsNullOrWhiteSpace(method.Summary))
            {
                sb.Append(" - " + method.Summary);
            }
            return(sb.ToString());
        }
Beispiel #11
0
        public IEncodedString DslLink(DocumentedMethod method)
        {
            var content = _context.SignatureRenderer.Render(
                _context.Language,
                method.Definition.GetMethodSignature(_context.UrlResolver),
                MethodRenderOption.Name |
                MethodRenderOption.Parameters |
                MethodRenderOption.Link);

            content = content.Replace("(ICakeContext, ", "(");
            content = content.Replace("(ICakeContext)", string.Empty);
            return(new RawString(content));
        }
Beispiel #12
0
        static void MatchMethod(List <IDocumentationMember> members, XmlNode node)
        {
            Identifier member = IdentifierFor.XmlString(node.Attributes["name"].Value);

            for (int i = 0; i < members.Count; i++)
            {
                var reflected = members[i] as ReflectedMethod;
                if (reflected != null && reflected.Match(member))
                {
                    members[i] = new DocumentedMethod(reflected.Name, node, reflected.Method, reflected.TargetType);
                }
            }
        }
Beispiel #13
0
 private static MethodRenderOption FixOptions(DocumentedMethod method, MethodRenderOption options)
 {
     if (method.Metadata.IsAlias)
     {
         if (method.Metadata.IsPropertyAlias)
         {
             options |= MethodRenderOption.PropertyAlias;
         }
         else
         {
             options |= MethodRenderOption.MethodAlias;
         }
     }
     return(options);
 }
Beispiel #14
0
        public void Text_Datagen_MethodsHaveSummaries()
        {
            foreach (MethodInfo info in typeof(ScottPlot.DataGen).GetMethods())
            {
                // skip abstract methods
                if (info.DeclaringType.IsAbstract && info.DeclaringType != typeof(ScottPlot.DataGen)) // Static classes count as abstract since they cannot be instantiated.....
                {
                    continue;
                }

                // skip inherited methods
                if (info.DeclaringType.FullName is null || info.DeclaringType.FullName == "System.Object")
                {
                    continue;
                }

                var m = new DocumentedMethod(info, LoadedXmlDocument);
                Assert.IsNotNull(m.Summary, $"{m.FullName} has no summary.");
            }
        }
Beispiel #15
0
        protected void AddDetailedInfo(DocumentedMethod p)
        {
            AddHeading(p.Name + "()", 3);
            if (!string.IsNullOrWhiteSpace(p.Summary))
            {
                Add($"**Summary:** {p.Summary}");
            }
            Add($"**Name:** `{p.FullName}`");
            Add($"**Signature:** `{p.Signature}`");

            if (p.Parameters.Any())
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"**Parameters:**");
                foreach (var p2 in p.Parameters)
                {
                    string summary = string.IsNullOrWhiteSpace(p2.Summary) ? "" : "- " + p2.Summary;
                    sb.AppendLine($"* `{p2.Type}` **{p2.Name}** {summary}");
                }
                Add(sb.ToString());
            }
        }
        public void Text_Plottables_MethodsHaveSummaries()
        {
            foreach (Type plottableType in ScottPlot.Cookbook.Locate.GetPlottableTypes())
            {
                foreach (MethodInfo info in ScottPlot.Cookbook.Locate.GetNotablePlottableMethods(plottableType))
                {
                    // skip abstract methods
                    if (info.DeclaringType.IsAbstract)
                    {
                        continue;
                    }

                    // skip inherited methods
                    if (info.DeclaringType.FullName is null)
                    {
                        continue;
                    }

                    var m = new DocumentedMethod(info, LoadedXmlDocument);
                    Assert.IsNotNull(m.Summary);
                }
            }
        }
Beispiel #17
0
        public static IHtmlString MethodClassificationName(this ApiServices context, DocumentedMethod type)
        {
            if (type != null)
            {
                if (type.Metadata.IsAlias)
                {
                    if (type.Metadata.IsPropertyAlias)
                    {
                        return(MvcHtmlString.Create("Cake Property Alias"));
                    }
                    return(MvcHtmlString.Create("Cake Method Alias"));
                }

                switch (type.MethodClassification)
                {
                case MethodClassification.Constructor:
                    return(MvcHtmlString.Create("Constructor"));

                case MethodClassification.EventAccessor:
                    return(MvcHtmlString.Create("Event"));

                case MethodClassification.ExtensionMethod:
                    return(MvcHtmlString.Create("Extension Method"));

                case MethodClassification.Method:
                    return(MvcHtmlString.Create("Method"));

                case MethodClassification.Operator:
                    return(MvcHtmlString.Create("Operator"));

                default:
                    return(MvcHtmlString.Create("Unknown"));
                }
            }
            return(MvcHtmlString.Create(string.Empty));
        }
 public MethodViewModel(ApiContext context, DocumentedMethod method, Content parent, string title)
     : base(context, parent, title)
 {
     _method = method;
 }
Beispiel #19
0
 /// <summary>
 /// Renders the syntax for a method.
 /// </summary>
 /// <param name="renderer">The syntax renderer to use.</param>
 /// <param name="method">The method.</param>
 /// <returns>The rendered syntax.</returns>
 public static string Render(this ISyntaxRenderer renderer, DocumentedMethod method)
 {
     return(renderer.Render(method.Definition.GetMethodSignature(null)));
 }
Beispiel #20
0
 public static IHtmlString ExtensionMethodLink(this ApiServices context, DocumentedMethod method)
 {
     return(MethodLink(context, method, MethodRenderOption.Name | MethodRenderOption.Parameters | MethodRenderOption.ExtensionMethod));
 }
Beispiel #21
0
 public static IHtmlString Syntax(this ApiServices context, DocumentedMethod method)
 {
     return(context.SyntaxRenderer.Render(method.Definition.GetMethodSignature(null)));
 }
Beispiel #22
0
 public string GetRoutePart(DocumentedMethod method)
 {
     return($"{method.Identity.GetHashCode():X8}".ToLowerInvariant());
 }
Beispiel #23
0
 public MethodViewModel(DocumentedMethod data)
 {
     _data = data;
 }
Beispiel #24
0
 public static void AppendMethod(this IBreadcrumbItem breadcrumb, ApiServices context, DocumentedMethod method)
 {
     if (method.Definition.IsConstructor)
     {
         breadcrumb.Append(new BreadcrumbItem("Constructor"));
     }
     else
     {
         var methodSignature = context.SignatureResolver.GetMethodSignature(method);
         breadcrumb.Append(new BreadcrumbItem(context.SignatureRenderer.Render(methodSignature, MethodRenderOption.Name), null));
     }
 }
Beispiel #25
0
 public IEncodedString Syntax(DocumentedMethod method)
 {
     return(new RawString(_context.SyntaxRenderer.Render(method)));
 }
Beispiel #26
0
 public IEncodedString Link(DocumentedMethod method)
 {
     return(Link(method.Definition));
 }
Beispiel #27
0
 public string GetLinkPart(DocumentedMethod method)
 {
     return(string.Format("{0:X8}", method.Identity.GetHashCode()).ToLowerInvariant());
 }