Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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.");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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.");
            }
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 16
0
        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);
                }
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 18
0
 public MethodViewModel(ApiContext context, DocumentedMethod method, Content parent, string title)
     : base(context, parent, title)
 {
     _method = method;
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 20
0
 public static IHtmlString ExtensionMethodLink(this ApiServices context, DocumentedMethod method)
 {
     return(MethodLink(context, method, MethodRenderOption.Name | MethodRenderOption.Parameters | MethodRenderOption.ExtensionMethod));
 }
Ejemplo n.º 21
0
 public static IHtmlString Syntax(this ApiServices context, DocumentedMethod method)
 {
     return(context.SyntaxRenderer.Render(method.Definition.GetMethodSignature(null)));
 }
Ejemplo n.º 22
0
 public string GetRoutePart(DocumentedMethod method)
 {
     return($"{method.Identity.GetHashCode():X8}".ToLowerInvariant());
 }
Ejemplo n.º 23
0
 public MethodViewModel(DocumentedMethod data)
 {
     _data = data;
 }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 25
0
 public IEncodedString Syntax(DocumentedMethod method)
 {
     return(new RawString(_context.SyntaxRenderer.Render(method)));
 }
Ejemplo n.º 26
0
 public IEncodedString Link(DocumentedMethod method)
 {
     return(Link(method.Definition));
 }
Ejemplo n.º 27
0
 public string GetLinkPart(DocumentedMethod method)
 {
     return(string.Format("{0:X8}", method.Identity.GetHashCode()).ToLowerInvariant());
 }